Пример #1
0
        public ActionResult Edit(int id = 0)
        {
            using (var db = new XkSystem.Models.DbContext())
            {
                var vm = new Models.SmsTo.Edit();
                if (id != 0)
                {
                    var tb = (from p in db.Table <Entity.tbSmsTo>()
                              where p.Id == id
                              select new Dto.SmsTo.Edit
                    {
                        Id = p.Id,
                        Mobile = p.Mobile,
                        No = p.No,
                        Remark = p.Remark,
                        Retry = p.Retry,
                        SmsId = p.tbSms.Id,
                        Status = p.Status,
                        SysUserId = p.tbSysUser.Id
                    }).FirstOrDefault();
                    if (tb != null)
                    {
                        vm.SmsToEdit = tb;
                    }
                }

                return(View(vm));
            }
        }
Пример #2
0
        public ActionResult Edit(Models.SmsTo.Edit vm)
        {
            using (var db = new XkSystem.Models.DbContext())
            {
                var error = new List <string>();
                if (error.Count == decimal.Zero)
                {
                    if (vm.SmsToEdit.Id == 0)
                    {
                        var tb = new Entity.tbSmsTo();
                        tb.Mobile = vm.SmsToEdit.Mobile;
                        tb.Remark = vm.SmsToEdit.Remark;
                        tb.Retry  = vm.SmsToEdit.Retry;
                        tb.Status = vm.SmsToEdit.Status;
                        tb.tbSms  = db.Set <Entity.tbSms>().Find(vm.SmsToEdit.SmsId);
                        db.Set <Entity.tbSmsTo>().Add(tb);
                        if (db.SaveChanges() > 0)
                        {
                            XkSystem.Areas.Sys.Controllers.SysUserLogController.Insert("添加了短信接收人");
                        }
                    }
                    else
                    {
                        var tb = (from p in db.Table <Entity.tbSmsTo>()
                                  where p.Id == vm.SmsToEdit.Id
                                  select p).FirstOrDefault();

                        if (tb != null)
                        {
                            tb.Mobile = vm.SmsToEdit.Mobile;
                            tb.Remark = vm.SmsToEdit.Remark;
                            tb.Retry  = vm.SmsToEdit.Retry;
                            tb.Status = vm.SmsToEdit.Status;
                            tb.tbSms  = db.Set <Entity.tbSms>().Find(vm.SmsToEdit.SmsId);
                            if (db.SaveChanges() > 0)
                            {
                                XkSystem.Areas.Sys.Controllers.SysUserLogController.Insert("修改了短信接收人");
                            }
                        }
                        else
                        {
                            error.AddError(Resources.LocalizedText.MsgNotFound);
                        }
                    }
                }
                return(Code.MvcHelper.Post(error, Url.Action("List")));
            }
        }