public static string Insert(Models.PaperSize.Edit vm) { using (var db = new XkSystem.Models.DbContext()) { var tb = new Dict.Entity.tbDictPaperSize(); tb.No = vm.PaperSizeEdit.No == null?db.Table <Dict.Entity.tbDictPaperSize>().Select(d => d.No).DefaultIfEmpty(0).Max() + 1 : (int)vm.PaperSizeEdit.No; tb.PaperSizeName = vm.PaperSizeEdit.PaperSizeName; tb.Height = vm.PaperSizeEdit.Height; tb.Width = vm.PaperSizeEdit.Width; db.Set <Dict.Entity.tbDictPaperSize>().Add(tb); db.SaveChanges(); return(string.Empty); } }
public ActionResult Edit(Models.PaperSize.Edit vm) { var error = new List <string>(); if (error.Count == decimal.Zero) { if (vm.PaperSizeEdit.Id == 0) { error.AddError(Service.PaperSize.Insert(vm)); } else { error.AddError(Service.PaperSize.Update(vm)); } } return(Code.MvcHelper.Post(error)); }
public static Models.PaperSize.Edit Edit(int id = 0) { using (var db = new XkSystem.Models.DbContext()) { var vm = new Models.PaperSize.Edit(); if (id != 0) { var tb = (from p in db.Table <Dict.Entity.tbDictPaperSize>() where p.Id == id select p).FirstOrDefault(); if (tb != null) { vm.PaperSizeEdit = tb; } } return(vm); } }
public static string Update(Models.PaperSize.Edit vm) { using (var db = new XkSystem.Models.DbContext()) { var tb = (from p in db.Table <Dict.Entity.tbDictPaperSize>() where p.Id == vm.PaperSizeEdit.Id select p).FirstOrDefault(); if (tb != null) { tb.No = vm.PaperSizeEdit.No == null?db.Table <Dict.Entity.tbDictPaperSize>().Select(d => d.No).DefaultIfEmpty(0).Max() + 1 : (int)vm.PaperSizeEdit.No; tb.PaperSizeName = vm.PaperSizeEdit.PaperSizeName; tb.Height = vm.PaperSizeEdit.Height; tb.Width = vm.PaperSizeEdit.Width; db.SaveChanges(); return(string.Empty); } else { return(Resources.LocalizedText.MsgNotFound); } } }