protected void AddBtn_Click(object sender, EventArgs e) { var usr = (User)Session["LoggedInUser"]; using (var ctx = new BudgetContext()) { ctx.Users.Attach(usr); var exp = new Expense { Amount = float.Parse(AmntTxt.Text), Date = DateTime.Parse(DateTxt.Text), Concept = ConceptTxt.Text, Tags = new List <ExpenseTag>() }; string[] tags = TagTxt.Text.Split(','); foreach (var item in tags) { var temp = ctx.ExpenseTags.Find(item.Trim()); if (temp == null) { temp = new ExpenseTag { ID = item.Trim() }; ctx.ExpenseTags.Add(temp); } exp.Tags.Add(temp); } usr.Expenses.Add(exp); ctx.SaveChanges(); ctx.Entry(usr).State = System.Data.Entity.EntityState.Detached; ConceptTxt.Text = ""; AmntTxt.Text = ""; DateTxt.Text = ""; TagTxt.Text = ""; } GridView1.DataBind(); }
public static ExpenseTag ToEntity(this ExpenseTagModel model, ExpenseTag destination) { return(model.MapTo(destination)); }
public static ExpenseTagModel ToModel(this ExpenseTag entity) { return(entity.MapTo <ExpenseTag, ExpenseTagModel>()); }