// // GET: /Member/Edit/By ID public ActionResult Edit(int id) { try { var member = _db.Members.Find(id); if (member != null) { var user = _db.Users.Find(member.UserName); var memberBloodGroups = SelectListItemExtension.PopulateDropdownList(_db.MemberBloodGroups.ToList <MemberBloodGroup>(), "Id", "BloodGroupName", isEdit: true, selectedValue: member != null ? member.MemberBloodGroupId.ToString() : "0").ToList(); var memberDistricts = SelectListItemExtension.PopulateDropdownList(_db.MemberDistricts.ToList <MemberDistrict>(), "Id", "DistrictName", isEdit: true, selectedValue: member != null ? member.MemberDistrictId.ToString() : "0").ToList(); var memberZones = SelectListItemExtension.PopulateDropdownList(_db.MemberZones.ToList <MemberZone>(), "Id", "ZoneName", isEdit: true, selectedValue: member != null ? member.MemberZoneId.ToString() : "0").ToList(); var memberHospitals = SelectListItemExtension.PopulateDropdownList(_db.MemberHospitals.ToList <MemberHospital>(), "Id", "HospitalName", isEdit: true, selectedValue: member != null ? member.MemberHospitalId.ToString() : "0").ToList(); var memberViewModel = new CreateOrEditMemberViewModel { MemberId = member.Id, UserName = user.UserName, UserEmail = user.Email, FirstName = member.FirstName, LastName = member.LastName, SurName = member.SurName, DateOfBirth = member.DateOfBirth, Address = member.Address, PhoneNumber = member.PhoneNumber, MobileNumber = member.MobileNumber, ThumbImageUrl = member.ThumbImageUrl, SmallImageUrl = member.SmallImageUrl, ddlMemberBloodGroups = memberBloodGroups, ddlMemberDistricts = memberDistricts, ddlMemberZones = memberZones, ddlMemberHospitals = memberHospitals, MemberBloodGroupId = member.MemberBloodGroupId, MemberBloodGroupName = member.MemberBloodGroup != null ? member.MemberBloodGroup.BloodGroupName : null, MemberDistrictId = member.MemberDistrictId, MemberDistrictName = member.MemberDistrict != null ? member.MemberDistrict.DistrictName : null, MemberZoneId = member.MemberZoneId, MemberZoneName = member.MemberZone != null ? member.MemberZone.ZoneName : null, MemberHospitalId = member.MemberHospitalId, MemberHospitalName = member.MemberHospital != null ? member.MemberHospital.HospitalName : null }; return(View(memberViewModel)); } else { return(RedirectToAction("Index", "Member")); } } catch (Exception ex) { ExceptionHelper.ExceptionMessageFormat(ex, true); return(RedirectToAction("Index", "Member")); } }
public ActionResult Edit(CreateOrEditMemberViewModel viewModel) { var memberBloodGroups = SelectListItemExtension.PopulateDropdownList(_db.MemberBloodGroups.ToList <MemberBloodGroup>(), "Id", "BloodGroupName", isEdit: true, selectedValue: viewModel.MemberBloodGroupId != 0 ? viewModel.MemberBloodGroupId.ToString() : "0").ToList(); var memberDistricts = SelectListItemExtension.PopulateDropdownList(_db.MemberDistricts.ToList <MemberDistrict>(), "Id", "DistrictName", isEdit: true, selectedValue: viewModel.MemberDistrictId != 0 ? viewModel.MemberDistrictId.ToString() : "0").ToList(); var memberZones = SelectListItemExtension.PopulateDropdownList(_db.MemberZones.ToList <MemberZone>(), "Id", "ZoneName", isEdit: true, selectedValue: viewModel.MemberZoneId != 0 ? viewModel.MemberZoneId.ToString() : "0").ToList(); var memberHospitals = SelectListItemExtension.PopulateDropdownList(_db.MemberHospitals.ToList <MemberHospital>(), "Id", "HospitalName", isEdit: true, selectedValue: viewModel.MemberHospitalId != 0 ? viewModel.MemberHospitalId.ToString() : "0").ToList(); viewModel.ddlMemberBloodGroups = memberBloodGroups; viewModel.ddlMemberDistricts = memberDistricts; viewModel.ddlMemberZones = memberZones; viewModel.ddlMemberHospitals = memberHospitals; try { if (ModelState.IsValid) { var member = new OSNB.Models.Member { Id = viewModel.MemberId, FirstName = viewModel.FirstName, LastName = viewModel.LastName, SurName = viewModel.SurName, DateOfBirth = viewModel.DateOfBirth, Address = viewModel.Address, PhoneNumber = viewModel.PhoneNumber, MobileNumber = viewModel.MobileNumber, ThumbImageUrl = viewModel.ThumbImageUrl, SmallImageUrl = viewModel.SmallImageUrl, MemberBloodGroupId = viewModel.MemberBloodGroupId, MemberDistrictId = viewModel.MemberDistrictId == 0 ? 1 : viewModel.MemberDistrictId, MemberZoneId = viewModel.MemberZoneId, MemberHospitalId = viewModel.MemberHospitalId, UserName = viewModel.UserName }; _db.Entry(member).State = EntityState.Modified; _db.SaveChanges(); return(RedirectToAction("Index", "Member")); //return Content(Boolean.TrueString); } return(Content(ExceptionHelper.ModelStateErrorFormat(ModelState))); } catch (Exception ex) { ExceptionHelper.ExceptionMessageFormat(ex, true); return(Content("Sorry! Unable to edit this member.")); } }
// // GET: /Member/Details/By ID public ActionResult Details(int id) { try { var member = _db.Members.Find(id); if (member != null) { var user = _db.Users.Find(member.UserName); var memberViewModel = new CreateOrEditMemberViewModel { MemberId = member.Id, UserName = user.UserName, UserEmail = user.Email, FirstName = member.FirstName, LastName = member.LastName, SurName = member.SurName, DateOfBirth = member.DateOfBirth, Address = member.Address, PhoneNumber = member.PhoneNumber, MobileNumber = member.MobileNumber, ThumbImageUrl = member.ThumbImageUrl, SmallImageUrl = member.SmallImageUrl, MemberBloodGroupName = member.MemberBloodGroup != null ? member.MemberBloodGroup.BloodGroupName : null, MemberDistrictName = member.MemberDistrict != null ? member.MemberDistrict.DistrictName : null, MemberZoneName = member.MemberZone != null ? member.MemberZone.ZoneName : null, MemberHospitalName = member.MemberHospital != null ? member.MemberHospital.HospitalName : null }; return(View(memberViewModel)); } else { return(RedirectToAction("Index", "Member")); } } catch (Exception ex) { ExceptionHelper.ExceptionMessageFormat(ex, true); return(RedirectToAction("Index", "Member")); } }
public ActionResult AddMember(string id) { try { var user = _db.Users.Find(id); if (user != null) { var memberBloodGroups = SelectListItemExtension.PopulateDropdownList(_db.MemberBloodGroups.ToList <MemberBloodGroup>(), "Id", "BloodGroupName").ToList(); var memberDistricts = SelectListItemExtension.PopulateDropdownList(_db.MemberDistricts.ToList <MemberDistrict>(), "Id", "DistrictName").ToList(); var memberZones = SelectListItemExtension.PopulateDropdownList(_db.MemberZones.ToList <MemberZone>(), "Id", "ZoneName").ToList(); var memberHospitals = SelectListItemExtension.PopulateDropdownList(_db.MemberHospitals.ToList <MemberHospital>(), "Id", "HospitalName").ToList(); var memberStatues = SelectListItemExtension.PopulateDropdownList(_db.MemberStatues.ToList <MemberStatus>(), "Id", "MemberStatusTitle").ToList(); var memberViewModel = new CreateOrEditMemberViewModel { UserName = user.UserName, UserEmail = user.Email, ddlMemberBloodGroups = memberBloodGroups, ddlMemberDistricts = memberDistricts, ddlMemberZones = memberZones, ddlMemberHospitals = memberHospitals, ddlMemberStatus = memberStatues }; return(View(memberViewModel)); } else { return(RedirectToAction("Index", "User")); } } catch (Exception ex) { ExceptionHelper.ExceptionMessageFormat(ex, true); return(RedirectToAction("Index", "User")); } }
public ActionResult AddMember(CreateOrEditMemberViewModel viewModel) { var memberBloodGroups = SelectListItemExtension.PopulateDropdownList(_db.MemberBloodGroups.ToList <MemberBloodGroup>(), "Id", "BloodGroupName", isEdit: true, selectedValue: viewModel.MemberBloodGroupId != 0 ? viewModel.MemberBloodGroupId.ToString() : "0").ToList(); var memberDistricts = SelectListItemExtension.PopulateDropdownList(_db.MemberDistricts.ToList <MemberDistrict>(), "Id", "DistrictName", isEdit: true, selectedValue: viewModel.MemberDistrictId != 0 ? viewModel.MemberDistrictId.ToString() : "0").ToList(); var memberZones = SelectListItemExtension.PopulateDropdownList(_db.MemberZones.ToList <MemberZone>(), "Id", "ZoneName", isEdit: true, selectedValue: viewModel.MemberZoneId != 0 ? viewModel.MemberZoneId.ToString() : "0").ToList(); var memberHospitals = SelectListItemExtension.PopulateDropdownList(_db.MemberHospitals.ToList <MemberHospital>(), "Id", "HospitalName", isEdit: true, selectedValue: viewModel.MemberHospitalId != 0 ? viewModel.MemberHospitalId.ToString() : "0").ToList(); var memberStatues = SelectListItemExtension.PopulateDropdownList(_db.MemberStatues.ToList <MemberStatus>(), "Id", "MemberStatusTitle").ToList(); viewModel.ddlMemberBloodGroups = memberBloodGroups; viewModel.ddlMemberDistricts = memberDistricts; viewModel.ddlMemberZones = memberZones; viewModel.ddlMemberHospitals = memberHospitals; viewModel.ddlMemberStatus = memberStatues; try { if (ModelState.IsValid) { var file = viewModel.ImageFile; if (file != null && file.ContentLength > 0) { var fileName = Path.GetFileName(file.FileName); var physicalPath = Path.Combine(Server.MapPath("~/Images"), fileName); // The files are not actually saved in this demo file.SaveAs(physicalPath); string imageUrl = @"/Images/" + fileName; viewModel.SmallImageUrl = imageUrl; viewModel.ThumbImageUrl = imageUrl; } var memberStatus = _db.MemberStatues.SingleOrDefault(x => x.Id == viewModel.MemberStatusId); var memberStatusList = new List <MemberStatus>(); memberStatusList.Add(memberStatus); OSNB.Models.Member model = new OSNB.Models.Member { FirstName = viewModel.FirstName, LastName = viewModel.LastName, SurName = viewModel.SurName, DateOfBirth = viewModel.DateOfBirth, Address = viewModel.Address, PhoneNumber = viewModel.PhoneNumber, MobileNumber = viewModel.MobileNumber, ThumbImageUrl = viewModel.ThumbImageUrl, SmallImageUrl = viewModel.SmallImageUrl, UserName = viewModel.UserName, MemberBloodGroupId = viewModel.MemberBloodGroupId, MemberDistrictId = viewModel.MemberDistrictId == 0 ? 1 : viewModel.MemberDistrictId, MemberZoneId = viewModel.MemberZoneId, MemberHospitalId = viewModel.MemberHospitalId, MemberStatues = memberStatusList }; _db.Members.Add(model); _db.SaveChanges(); return(RedirectToAction("Index", "Member")); } //return Content(ExceptionHelper.ModelStateErrorFormat(ModelState)); return(View(viewModel)); } catch (Exception ex) { ExceptionHelper.ExceptionMessageFormat(ex, true); return(View(viewModel)); } }
public ActionResult CreateOrEdit([Bind(Include = "Name,MemberType,Index,TeamIndex")] CreateOrEditMemberViewModel member) { Member memberActual = new Member { Name = member.Name, MemberType = member.MemberType }; if (ModelState.IsValid) { memberActual.Team = member.TeamIndex == "-1" ? null : ((List <Team>)TempData["TeamsListGivenMC"]) [int.Parse(member.TeamIndex)]; db.Teams.Attach(memberActual.Team); if (member.Index == null || member.Index == "-1") { int i = 0; Random r = new Random(); do { memberActual.Id = r.Next(); i++; if (i > 1000) { return(View(memberActual)); } } while (db.Members.Any(o => o.Id == memberActual.Id)); db.Members.AddOrUpdate(memberActual); db.SaveChanges(); return(RedirectToAction("Index")); } memberActual.Id = ((List <Member>)TempData["MembersListGivenMC"]) [int.Parse(member.Index)] .Id; db.Entry(memberActual).State = EntityState.Modified; //db.Members.AddOrUpdate(memberActual); db.SaveChanges(); var m = db.Members.Single(n => n.Id == memberActual.Id); var t = db.Teams.Single(n => n.Id == memberActual.Team.Id); m.Team = t; db.Entry(m).State = EntityState.Unchanged; db.Entry(t).State = EntityState.Unchanged; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(member)); }
public ActionResult Edit(CreateOrEditMemberViewModel viewModel, HttpPostedFileBase ImageFile) { var memberBloodGroups = SelectListItemExtension.PopulateDropdownList(_db.MemberBloodGroups.ToList <MemberBloodGroup>(), "Id", "BloodGroupName", isEdit: true, selectedValue: viewModel.MemberBloodGroupId != 0 ? viewModel.MemberBloodGroupId.ToString() : "0").ToList(); var memberDistricts = SelectListItemExtension.PopulateDropdownList(_db.MemberDistricts.ToList <MemberDistrict>(), "Id", "DistrictName", isEdit: true, selectedValue: viewModel.MemberDistrictId != 0 ? viewModel.MemberDistrictId.ToString() : "0").ToList(); var memberZones = SelectListItemExtension.PopulateDropdownList(_db.MemberZones.ToList <MemberZone>(), "Id", "ZoneName", isEdit: true, selectedValue: viewModel.MemberZoneId != 0 ? viewModel.MemberZoneId.ToString() : "0").ToList(); var memberHospitals = SelectListItemExtension.PopulateDropdownList(_db.MemberHospitals.ToList <MemberHospital>(), "Id", "HospitalName", isEdit: true, selectedValue: viewModel.MemberHospitalId != 0 ? viewModel.MemberHospitalId.ToString() : "0").ToList(); var memberStatues = SelectListItemExtension.PopulateDropdownList(_db.MemberStatues.ToList <MemberStatus>(), "Id", "MemberStatusTitle").ToList(); viewModel.ddlMemberBloodGroups = memberBloodGroups; viewModel.ddlMemberDistricts = memberDistricts; viewModel.ddlMemberZones = memberZones; viewModel.ddlMemberHospitals = memberHospitals; viewModel.ddlMemberStatus = memberStatues; try { if (ModelState.IsValid) { //you can put your existing save code here if (ImageFile != null && ImageFile.ContentLength > 0) { var uploadDir = "~/Images"; var imagePath = Path.Combine(Server.MapPath(uploadDir), ImageFile.FileName); var imageUrl = Path.Combine(uploadDir, ImageFile.FileName); ImageFile.SaveAs(imagePath); var imageFile = @"/Images/" + ImageFile.FileName; viewModel.ThumbImageUrl = imageFile; viewModel.SmallImageUrl = imageFile; } var memberStatus = _db.MemberStatues.SingleOrDefault(x => x.Id == viewModel.MemberStatusId); var memberStatusList = new List <MemberStatus>(); memberStatusList.Add(memberStatus); var member = new OSNB.Models.Member { Id = viewModel.MemberId, FirstName = viewModel.FirstName, LastName = viewModel.LastName, SurName = viewModel.SurName, DateOfBirth = viewModel.DateOfBirth, Address = viewModel.Address, PhoneNumber = viewModel.PhoneNumber, MobileNumber = viewModel.MobileNumber, ThumbImageUrl = viewModel.ThumbImageUrl, SmallImageUrl = viewModel.SmallImageUrl, MemberBloodGroupId = viewModel.MemberBloodGroupId, MemberDistrictId = viewModel.MemberDistrictId == 0 ? 1 : viewModel.MemberDistrictId, MemberZoneId = viewModel.MemberZoneId, MemberHospitalId = viewModel.MemberHospitalId, UserName = viewModel.UserName, MemberStatues = memberStatusList }; _db.Entry(member).State = EntityState.Modified; _db.SaveChanges(); return(RedirectToAction("Index", "Member")); //return Content(Boolean.TrueString); } return(Content(ExceptionHelper.ModelStateErrorFormat(ModelState))); } catch (Exception ex) { ExceptionHelper.ExceptionMessageFormat(ex, true); return(Content("Sorry! Unable to edit this member.")); } }
public ActionResult CreateOrEdit(int?id) { var teams = db.Teams.ToList(); TempData["TeamsListGivenMC"] = teams; ViewBag.Id = id; var members = db.Members.ToList(); TempData["MembersListGivenMC"] = members; ViewBag.MembersList = members; int teamIdReceived; try { teamIdReceived = (members.Find(n => n.Id == id).Team.Id); } catch (Exception) { teamIdReceived = -1; } List <SelectListItem> selectList = new List <SelectListItem>(); for (int i = 0; i < teams.Count; i++) { selectList.Add(new SelectListItem { Selected = id != null ? (teams[i].Id == teamIdReceived) : false, Text = teams[i].Name, Value = i.ToString() }); } ViewBag.TeamsList = selectList; List <SelectListItem> membersSelectList = new List <SelectListItem>(); membersSelectList.Add(new SelectListItem { Selected = false, Text = "None", Value = "-1" }); for (int i = 0; i < members.Count; i++) { membersSelectList.Add(new SelectListItem { Selected = id != null ? (members[i].Id == id) : false, Text = members[i].Name, Value = i.ToString() }); } CreateOrEditMemberViewModel ToGive = new CreateOrEditMemberViewModel { membersList = membersSelectList, teamsList = selectList }; var member = members.Find(n => n.Id == id); if (member != null) { ToGive.Name = member.Name; ToGive.MemberType = member.MemberType; } return(View(ToGive)); }