示例#1
0
        public ActionResult Edit(string id)
        {
            bool isEdit = !string.IsNullOrEmpty(id);
            var  vd     = new Schedule_EditVD();

            var activity = _activityService.GetFullList(z => true, z => z.IsPublish, OrderingType.Descending);

            if (activity.Count < 1)
            {
                base.SetMessager(MessageType.danger, "请先添加活动!");
                return(RedirectToAction("Index"));
            }

            vd.ActivityList = activity;
            if (isEdit)
            {
                var model = _scheduleService.GetObject(z => z.Id == id);
                if (model == null)
                {
                    base.SetMessager(MessageType.danger, "信息不存在!");
                    return(RedirectToAction("Index"));
                }

                vd.Id         = model.Id;
                vd.Name       = model.Name;
                vd.Address    = model.Address;
                vd.ActivityId = model.ActivityId;
                vd.Activity   = model.Activity;

                vd.Remark     = model.Remark;
                vd.Desc       = model.Desc;
                vd.SignNumber = model.SignNumber;
                vd.StartTime  = model.StartTime;
                vd.EndTime    = model.EndTime;
                vd.Flag       = model.Flag;
                //vd.Note = model.Note;
            }
            else
            {
                vd.SignNumber = "01,02";
                vd.CreateTime = DateTime.Now;
                vd.StartTime  = DateTime.Now.Date;
                vd.EndTime    = DateTime.Now.AddDays(1).Date.AddSeconds(-1);
            }
            vd.IsEdit = isEdit;
            return(View(vd));
        }
示例#2
0
        public async Task <IActionResult> Edit(Schedule_EditVD model)
        {
            bool isEdit = !string.IsNullOrEmpty(model.Id);

            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            Schedule account = null;

            if (isEdit)
            {
                account = _scheduleService.GetObject(z => z.Id == model.Id);
                if (account == null)
                {
                    base.SetMessager(MessageType.danger, "信息不存在!");
                    return(RedirectToAction("Index"));
                }

                account.UpdateTime  = DateTime.Now;
                account.UpdatorId   = UserName;
                account.UpdatorName = AdminUser == null ? "" : AdminUser.RealName;
            }
            else
            {
                account = new Schedule()
                {
                    Id          = Guid.NewGuid().ToString("N"),
                    Name        = model.Name,
                    Address     = model.Address,
                    Desc        = model.Desc,
                    Flag        = false,
                    StartTime   = model.StartTime,
                    EndTime     = model.EndTime,
                    SignNumber  = model.SignNumber,
                    Remark      = model.Remark,
                    ActivityId  = model.ActivityId,
                    CreateTime  = DateTime.Now,
                    Sort        = model.Sort,
                    UpdateTime  = DateTime.Now,
                    CreatorId   = UserName,
                    Creator     = AdminUser == null ? "" : AdminUser.RealName,
                    UpdatorId   = UserName,
                    UpdatorName = AdminUser == null ? "" : AdminUser.RealName,
                };
            }
            try
            {
                await TryUpdateModelAsync(account, "", v => v.Name
                                          , v => v.Address
                                          , v => v.ActivityId
                                          , v => v.Desc
                                          , v => v.UpdatorId
                                          , v => v.UpdatorName
                                          , v => v.Remark
                                          , v => v.Desc
                                          , v => v.Sort
                                          , v => v.StartTime
                                          , v => v.EndTime
                                          , v => v.Flag
                                          , v => v.SignNumber);


                _scheduleService.SaveObject(account);
                base.SetMessager(MessageType.success, $"{(isEdit ? "修改" : "新增")}成功!");
                return(RedirectToAction("Index"));
            }
            catch (Exception)
            {
                base.SetMessager(MessageType.danger, $"{(isEdit ? "修改" : "新增")}失败!");
                return(RedirectToAction("Index"));
            }
        }