public async Task <ActionResult> Create(GiftCreateViewModel data) { var imageErrorMsg = new StringBuilder(); User current_user = Session["user"] as User; HttpPostedFileBase image = Request.Files["Image"]; if (ModelState.IsValid && image.ContentLength > 0 && (_fileHandler.CheckContentType(image, new List <string> { "image/jpg", "image/jpeg", "image/svg+xml", "image/png" }, imageErrorMsg) & _fileHandler.CheckSize(image, 2 * StorageUnits.Megabyte, imageErrorMsg))) { string imagePath = _fileHandler.Upload(image); var new_gift = new Gift { Title = data.Title, Quantity = data.Quantity, Image = imagePath, Status = GiftStatus.InCheckUp, Content = data.Content, UserID = current_user.Id }; await _unitofWork.Gifts.Create(new_gift); return(RedirectToAction("List", "Gift")); } ModelState.AddModelError("image", imageErrorMsg.ToString()); return(View()); }
public GiftCreateViewModel GetEditDetail(long id, JoinItemTypeEnum joinItemType) { var ds = dal.GetEditDetail(id, joinItemType.GetHashCode()); GiftCreateViewModel model = new GiftCreateViewModel() { Gift = ModelConvertHelper <Gift> .ConverToModel(ds.Tables[0]), GiftFees = ModelConvertHelper <GiftFee> .ConvertToList(ds.Tables[1]), JoinItemQues = ModelConvertHelper <JoinItemQuestionExt> .ConvertToList(ds.Tables[2]) }; return(model); }
public ActionResult Edit(long id) { if (id > 0) { int type = 0; type = GiftBLL.Instance.GetModel(id).GType.Value; ViewBag.ID = type; GiftCreateViewModel model = GiftBLL.Instance.GetEditDetail(id, type == 1 ? JoinItemTypeEnum.Gift : type == 2 ? JoinItemTypeEnum.DataAnalysis : JoinItemTypeEnum.KeCheng); return(View(model)); } else { return(RedirectToAction("Index", "Home")); } }
public ActionResult Edit(GiftCreateViewModel model) { ResultInfo ri = new ResultInfo(); if (model.Gift.GiftID == model.GiftFees[0].GiftID) { Gift _model = GiftBLL.Instance.GetModel(model.Gift.GiftID); if (_model != null) { if (_model.IsDelete == 0) { BeginTran(); _model.GiftName = model.Gift.GiftName; _model.GiftDesc = model.Gift.GiftDesc; _model.GiftImgs = model.Gift.GiftImgs; _model.GiftInfo = HttpUtility.UrlDecode(model.Gift.GiftInfo); _model.OpenJoinItem = model.Gift.OpenJoinItem; if (GiftBLL.Instance.Update(_model, Tran).Ok) { var finalFees = model.GiftFees.Where(item => { return(item.Fee.HasValue && item.FeeCount.HasValue && item.FeeType.HasValue && item.FeeName.IsNotNullOrEmpty()); }); //更新费用 foreach (GiftFee fee in finalFees) { if (fee.GiftFeeId > 0) { if (fee.GiftID == _model.GiftID) { //更新 var feeModel = GiftFeeBLL.Instance.GetModel(fee.GiftFeeId); feeModel.FeeType = fee.FeeType; feeModel.FeeName = fee.FeeName; feeModel.Fee = fee.Fee; feeModel.FeeCount = fee.FeeCount; feeModel.GiftID = _model.GiftID; if (GiftFeeBLL.Instance.Update(feeModel, Tran).Ok) { ri.Ok = true; } else { ri.Ok = false; break; } } else { ri.Ok = false; ri.Msg = "该费用列表异常!"; break; } } else { fee.GiftID = model.Gift.GiftID; if (GiftFeeBLL.Instance.Add(fee, Tran) > 0) { ri.Ok = true; } else { ri.Ok = false; break; } } } if (ri.Ok) { //更新报名填写项 if (model.JoinItemQues != null) { var finalJoins = model.JoinItemQues.Where(item => { return(item.ItemName.IsNotNullOrEmpty()); }); foreach (var item in finalJoins) { if (item.JoinItemQuestionExtId > 0) { if (item.MainID == _model.GiftID) { //更新 var joinItem = JoinItemQuestionExtBLL.Instance.GetModel(item.JoinItemQuestionExtId); joinItem.ItemName = item.ItemName; joinItem.UpdateTime = DateTime.Now; joinItem.UpdateUser = UserID.ToString(); if (JoinItemQuestionExtBLL.Instance.Update(joinItem, Tran).Ok) { ri.Ok = true; } else { ri.Ok = false; break; } } else { ri.Ok = false; break; } } else { item.MainID = model.Gift.GiftID; item.MainType = (_model.GType == 1 ? JoinItemTypeEnum.Gift : _model.GType == 2 ? JoinItemTypeEnum.DataAnalysis : JoinItemTypeEnum.KeCheng).GetHashCode(); item.CreateTime = DateTime.Now; item.CreateUser = UserID.ToString(); item.UpdateTime = DateTime.Now; item.UpdateUser = UserID.ToString(); item.IsDelete = 0; item.IsMustWrite = 1; if (JoinItemQuestionExtBLL.Instance.Add(item, Tran) > 0) { ri.Ok = true; } else { ri.Ok = false; break; } } } } if (ri.Ok) { ri.Msg = "编辑成功"; Commit(); } else { RollBack(); } } else { RollBack(); } } } else { ri.Msg = "该商品已被删除,编辑失败"; } } else { ri.Msg = "异常"; } } else { ri.Msg = "异常"; } return(Result(ri)); }
public ActionResult Create(GiftCreateViewModel model) { ResultInfo ri = new ResultInfo(); if (ModelState.IsValid) { try { var gift = model.Gift; NoticeTypeEnum noticeType; string desc = string.Empty; int joinItemType = 2; if (gift.GType == 1) { desc = "礼物"; noticeType = NoticeTypeEnum.Gift_Add; joinItemType = 2; } else if (gift.GType == 2) { desc = "数据"; noticeType = NoticeTypeEnum.DataAnalysis_Add; joinItemType = 4; } else { desc = "课程"; noticeType = NoticeTypeEnum.KeCheng_Add; joinItemType = 3; } if (!string.IsNullOrEmpty(gift.GiftName)) { if (!string.IsNullOrEmpty(gift.GiftDesc)) { if (!string.IsNullOrEmpty(gift.GiftInfo)) { BeginTran(); gift.GiftInfo = HttpUtility.UrlDecode(gift.GiftInfo); gift.GiftCreateUserID = UserID; gift.GiftCreateTime = DateTime.Now; gift.PVCount = 0; gift.IsDelete = 0; gift.OpenJoinItem = gift.OpenJoinItem ?? 0; int result = GiftBLL.Instance.Add(gift, Tran); if (result > 0) { var finalFees = model.GiftFees.Where(item => { return(item.Fee.HasValue && item.FeeCount.HasValue && item.FeeType.HasValue && item.FeeName.IsNotNullOrEmpty()); }); //处理价格信息 foreach (var item in finalFees) { item.GiftID = result; item.FeeType = item.FeeType ?? 0; if (GiftFeeBLL.Instance.Add(item, Tran) < 1) { result = 0; break; } } if (result > 0) { if (gift.OpenJoinItem == 1) { #region 添加活动报名填写项 if (model.JoinItemQues != null) { var finalJoins = model.JoinItemQues.Where(item => { return(item.ItemName.IsNotNullOrEmpty()); }); foreach (var item in finalJoins) { item.IsDelete = 0; item.CreateTime = DateTime.Now; item.UpdateTime = DateTime.Now; item.CreateUser = UserID.ToString(); item.UpdateUser = UserID.ToString(); item.IsMustWrite = 1; item.MainID = result; item.MainType = joinItemType; if (JoinItemQuestionExtBLL.Instance.Add(item, Tran) < 1) { result = 0; break; } } } #endregion } if (result > 0) { Commit(); string uri = $"/gift/detail/{result}"; ri.Ok = true; ri.Msg = "{0}创建成功".FormatWith(desc); ri.Url = uri; //通知 NoticeBLL.Instance.OnAdd_Notice_Liker(UserInfo.UserName, UserID, uri, gift.GiftName, noticeType, GetDomainName); } else { RollBack(); ri.Msg = "{0}创建失败".FormatWith(desc); } } else { RollBack(); ri.Msg = "{0}创建失败".FormatWith(desc); } } else { RollBack(); ri.Msg = "{0}创建失败".FormatWith(desc); } } else { ri.Msg = "{0}详细介绍不能为空".FormatWith(desc); } } else { ri.Msg = "{0}简介不能为空".FormatWith(desc); } } else { ri.Msg = "{0}名称不能为空".FormatWith(desc); } } catch (Exception e) { } } return(Result(ri)); }