예제 #1
0
        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();
        }
예제 #2
0
 public static ExpenseTag ToEntity(this ExpenseTagModel model, ExpenseTag destination)
 {
     return(model.MapTo(destination));
 }
예제 #3
0
 public static ExpenseTagModel ToModel(this ExpenseTag entity)
 {
     return(entity.MapTo <ExpenseTag, ExpenseTagModel>());
 }