Created
April 18, 2017 10:29
-
-
Save mshirdel/e0b35d7220923356124c95f657e28716 to your computer and use it in GitHub Desktop.
Insert Action in EF Code First
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public override void Up() | |
{ | |
var actions = new Dictionary<string, string>() { | |
{ "ActionName", "توضیح" } | |
}; | |
using (CRMEntities db = new CRMEntities()) | |
{ | |
foreach (var item in actions) | |
{ | |
var actionItem = db.Actions.FirstOrDefault(a => a.ActionName == item.Key); | |
if (actionItem != null) | |
return; | |
db.Actions.Add(new Core.Action | |
{ | |
ActionName = item.Key, | |
ApplicationId = Guid.Parse("124035CB-7903-44CD-97CE-FDC01571900F"), | |
CategoryId = 10, | |
Description = item.Value | |
}); | |
db.SaveChanges(); | |
} | |
} | |
} | |
public override void Down() | |
{ | |
using (CRMEntities db = new CRMEntities()) | |
{ | |
var actionsToDelete = new List<String>() { "َActionName", "ActionName", "ActionName" }; | |
foreach (var item in actionsToDelete) | |
{ | |
var actionItem = db.Actions.FirstOrDefault(a => a.ActionName == item); | |
if (actionItem != null) | |
{ | |
db.Actions.Remove(actionItem); | |
db.SaveChanges(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment