public ActionResult Edit(TeamMember member, IEnumerable<HttpPostedFileBase> Images) { ViewBag.MainNav = Navigator.Main.ABOUT; ViewBag.SubNav = Navigator.Sub.TEAM; if (ModelState.IsValid) { if (Images != null && Images.Count() > 0 && !ImageService.IsValid(Images)) { TempData["ErrorMessage"] = "Member Failed To Edit, Invalid Image File"; } else { int new_id = teamService.UpdateMember(member, Images); if (new_id > 0) { TempData["SuccessMessage"] = "Member Edited Successfully"; return RedirectToAction("Edit", new { id = new_id }); } else TempData["ErrorMessage"] = "Member Failed To Edited"; } } return View(); }
public int AddNewMember(TeamMember member, IEnumerable<HttpPostedFileBase> Images = null) { DbContext.TeamMembers.Add(member); try { DbContext.SaveChanges(); } catch (Exception ex) { // logService.WriteError(ex.Message, ex.Message, ex.StackTrace, ex.Source); return -1; } if (member.ID > 0 && Images != null && Images.Count() > 0 && Images.Where(i => i != null).Count() > 0) { AddMemberImages(member.ID, Images); } return member.ID; }
public int UpdateMember(TeamMember member, IEnumerable<HttpPostedFileBase> Images = null) { TeamMember old_member = DbContext.TeamMembers.Where(m => m.ID == member.ID).FirstOrDefault(); if (old_member != null) { old_member.Career = member.Career; old_member.CareerAr = member.CareerAr; old_member.CurrentRole = member.CurrentRole; old_member.CurrentRoleAr = member.CurrentRoleAr; old_member.Education = member.Education; old_member.EducationAr = member.EducationAr; old_member.Email = member.Email; old_member.Expertise = member.Expertise; old_member.ExpertiseAr = member.ExpertiseAr; old_member.FullName = member.FullName; old_member.FullNameAr = member.FullNameAr; old_member.IsOnline = member.IsOnline; old_member.Linkedin = member.Linkedin; old_member.Twitter = member.Twitter; old_member.Type = member.Type; DbContext.SaveChanges(); } else return -1; if (member.ID > 0 && Images != null && Images.Where(i=> i != null).Count() > 0) { if(old_member.ImageURL != null && old_member.ImageURL != "") ImageService.DeleteImage(HttpContext.Current.Server.MapPath("~" + old_member.ImageURL)); AddMemberImages(member.ID, Images); } try { return old_member.ID; } catch (Exception ex) { // logService.WriteError(ex.Message, ex.Message, ex.StackTrace, ex.Source); return -1; } }