public ActionResult AddScheme(AddSchemeViewModel model)
        {
            ServiceResult result = new ServiceResult();

            try
            {
                SchemeItem entity = new SchemeItem();
                entity.MediaID     = model.id;
                entity.StartTime   = Convert.ToDateTime(model.startTime);
                entity.EndTime     = Convert.ToDateTime(model.endTime);
                entity.Price       = Convert.ToDecimal(model.price);
                entity.PeriodCode  = model.periodCode;
                entity.PeriodCount = model.periodCount;
                if (string.IsNullOrEmpty(model.Name) && model.schemeId != 0)
                {
                    entity.SchemeID = model.schemeId;
                    if (SchemeItemService.GetALL().Any(x => x.MediaID == model.id && x.SchemeID == model.schemeId))
                    {
                        result.AddServiceError("该方案已经包含了此媒体");
                        result.Message = "该方案已经包含了此媒体!";
                    }
                }
                else
                {
                    Scheme scheme = new Scheme()
                    {
                        AddTime     = DateTime.Now,
                        Name        = model.Name,
                        Description = model.Description,
                        LastTime    = DateTime.Now,
                        MemberID    = CookieHelper.MemberID
                    };
                    SchemeService.Create(scheme);
                    entity.SchemeID = scheme.ID;
                }
                if (result.Success)
                {
                    SchemeItemService.Create(entity);
                    result.Message = "加入方案成功!";
                }
            }
            catch (Exception ex)
            {
                result.Message = "加入方案失败!";
                result.AddServiceError(Utilities.GetInnerMostException(ex));
                LogHelper.WriteLog("用户:" + CookieHelper.MemberID + "加入方案失败!", ex);
            }
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Example #2
0
        public ActionResult Add(SchemeAddViewModel model)
        {
            ViewBag.MenuItem = "scheme-add";
            ServiceResult result = new ServiceResult();

            TempData["Service_Result"] = result;
            if (ModelState.IsValid)
            {
                try
                {
                    var memberID = Convert.ToInt32(CookieHelper.UID);

                    Scheme entity = new Scheme()
                    {
                        Name        = model.Name,
                        Description = model.Description,
                        MemberID    = memberID,
                        AddTime     = DateTime.Now,
                        LastTime    = DateTime.Now,
                    };
                    SchemeService.Create(entity);
                    result.Message = "媒体方案保存成功!";
                    return(Redirect(Url.Action("index")));
                }
                catch (Exception ex)
                {
                    result.Message = Utilities.GetInnerMostException(ex);
                    result.AddServiceError(result.Message);
                    LogHelper.WriteLog("用户:" + CookieHelper.MemberID + "媒体方案保存失败!", ex);
                }
            }
            else
            {
                result.Message = "表单输入有误!";
                result.AddServiceError("表单输入有误!");
            }
            return(View(model));
        }