public ActionResult Create(AwardView awardView) { Award award = null; try { if (ModelState.IsValid && awardView.Image != null) { string fileName = SetPhotoPath(awardView); string path = "/img/" + Path.GetFileName(awardView.Image.FileName); award = new Award() { Title = awardView.Title, Description = awardView.Description, ImagePath = path }; Repository.AddAward(award); Repository.Save(); return(RedirectToAction("Index")); } } catch (DataException) { ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator."); } return(View(award)); }
public ActionResult CreateAward(AwardView awardInfo) { //Check that Departmnet Info is Not Null if (awardInfo == null) { throw new ArgumentNullException(nameof(awardInfo)); } //Validate Model if (!ModelState.IsValid) { var model = this.awardService.CreateAwardUpdatedView(awardInfo, ""); return(View("CreateAward", model)); } //Process The Department Information var processingMessage = awardService.ProcessAwardInfo(awardInfo); //Check if the Processing Message is Not Empty //If it is not empty, Means there is no error if (!string.IsNullOrEmpty(processingMessage)) { var model = this.awardService.CreateAwardUpdatedView(awardInfo, processingMessage); return(this.View("CreateAward", model)); } return(this.RedirectToAction("AwardList")); }
public ActionResult EditAward(AwardView awardInfo) { if (awardInfo == null) { throw new ArgumentNullException(nameof(awardInfo)); } if (!ModelState.IsValid) { var model = this.awardService.CreateAwardUpdatedView(awardInfo, ""); return(View("EditAward", model)); } var processingMessage = awardService.ProcessEditAwardInfo(awardInfo); if (!string.IsNullOrEmpty(processingMessage)) { var model = this.awardService.CreateAwardUpdatedView(awardInfo, processingMessage); return(this.View("EditAward", model)); } return(this.RedirectToAction("AwardList", new { awardInfo.AwardId })); }
//public new int InsertView(int num,AwardView objModalSrc) //{ // return AddOrUpdate(num, objModalSrc, true); //} //public new int UpdateView(int num,AwardView objModalSrc) //{ // return AddOrUpdate(num, objModalSrc, false); //} private int AddOrUpdate(int num, AwardView objModalSrc, bool bolAdd) { AwardView objView = objModalSrc; if (objView == null) { return(-1); } int iRet; AwardEntity award = new AwardEntity(); for (int i = 0; i < num; i++) { award = new AwardEntity { PollingId = objModalSrc.PollingId, Type = "polling", SecurityCode = NumberCheck(7, true), Status = "已中奖", AccessDate = DateTime.Now }; if (bolAdd) { iRet = Repository.Insert(award); } else { iRet = Repository.Update(award); } } return(1); }
/// <summary> /// Creates the award view. /// </summary> /// <returns></returns> public IAwardView CreateAwardView() { //if (awardId == null) throw new ArgumentNullException(nameof(awardId)); var viewModel = new AwardView { //AwardId = awardId, }; return(viewModel); }
private string SetPhotoPath(AwardView awardView) { string fileName = Path .Combine(hosting.WebRootPath, "img", Path.GetFileName(awardView.Image.FileName)); using (var stream = new FileStream(fileName, FileMode.Create)) { awardView.Image.CopyTo(stream); } return(fileName); }
/// <summary> /// Creates the award update view. /// </summary> /// <param name="awardInfo">The award information.</param> /// <returns></returns> /// <exception cref="ArgumentNullException">awardInfo</exception> public IAwardView CreateAwardUpdateView(IAward awardInfo) { if (awardInfo == null) { throw new ArgumentNullException(nameof(awardInfo)); } var awardView = new AwardView { AwardId = awardInfo.AwardId, UserId = awardInfo.UserId, AwardName = awardInfo.AwardName, AwardYear = awardInfo.AwardYear, DateCreated = awardInfo.DateCreated, IsActive = awardInfo.IsActive, }; return(awardView); }
/// <summary> /// Creates the edit award view. /// </summary> /// <param name="awardInfo">The award information.</param> /// <returns></returns> /// <exception cref="ArgumentNullException">awardInfo</exception> public IAwardView CreateEditAwardView(IAward awardInfo) { if (awardInfo == null) { throw new ArgumentNullException(nameof(awardInfo)); } //if (awardCollection == null) throw new ArgumentNullException(nameof(awardCollection)); //var departmentDDL = // GetDropDownList.DepartmentListItems(departmentCollection, departmentInfo.ParentDepartmentId); var returnAward = new AwardView { AwardId = awardInfo.AwardId, UserId = awardInfo.UserId, AwardName = awardInfo.AwardName, AwardYear = awardInfo.AwardYear, IsActive = awardInfo.IsActive }; return(returnAward); }