public ActionResult Create([Bind(Include = "OfficeLocationId,OfficeAddress,City,TelePhoneNo,Fax,Email,CompanyId")] OfficeLocationModel officeLocationModel) { UserPermissionAction("OfficeLocation", RoleAction.view.ToString()); CheckPermission(); TempData["ShowMessage"] = ""; TempData["MessageBody"] = ""; try { if (ModelState.IsValid) { Mapper.CreateMap <CommunicationApp.Models.OfficeLocationModel, CommunicationApp.Entity.OfficeLocation>(); CommunicationApp.Entity.OfficeLocation OfficeLocation = Mapper.Map <CommunicationApp.Models.OfficeLocationModel, CommunicationApp.Entity.OfficeLocation>(officeLocationModel); if (OfficeLocation != null) { if (OfficeLocation.CompanyId != 0) { OfficeLocation.CompanyId = Convert.ToInt32(Session["CompanyID"]) == null ? 0 : Convert.ToInt32(Session["CompanyID"]); List <double> ListLatLong = GoogleOperation.GetLatLong(OfficeLocation.City); OfficeLocation.Latitude = (decimal)(ListLatLong.Count > 0 ? ListLatLong[0] : 0); OfficeLocation.Longitude = (decimal)(ListLatLong.Count > 0 ? ListLatLong[1] : 0); _OfficeLocationService.InsertOfficeLocation(OfficeLocation); TempData["ShowMessage"] = "success"; TempData["MessageBody"] = "Office Location successfully inserted"; } else { TempData["ShowMessage"] = "error"; TempData["MessageBody"] = "Lacation not saved successfully."; } return(RedirectToAction("index")); } } var errors = ModelState.Where(x => x.Value.Errors.Count > 0).Select(x => new { x.Key, x.Value.Errors }).ToArray(); var modelStateErrors = this.ModelState.Keys.SelectMany(key => this.ModelState[key].Errors); return(View(officeLocationModel)); } catch (Exception ex) { TempData["ShowMessage"] = "error"; TempData["MessageBody"] = ex.Message.ToString(); } return(View()); }
public ActionResult EditOfficeLocation([Bind(Include = "OfficeLocationId,OfficeAddress,City,TelePhoneNo,Fax,Email,Latitude,Longitude")] OfficeLocationModel officeLocationModel) { UserPermissionAction("customer", RoleAction.view.ToString()); CheckPermission(); TempData["ShowMessage"] = ""; TempData["MessageBody"] = ""; try { if (ModelState.IsValid) { var OfficeLocationFound = _OfficeLocationService.GetOfficeLocations().Where(c => (c.OfficeAddress.Trim() == officeLocationModel.OfficeAddress.Trim()) && c.OfficeLocationId != officeLocationModel.OfficeLocationId).FirstOrDefault(); if (OfficeLocationFound == null) { var officeLocation = _OfficeLocationService.GetOfficeLocation(officeLocationModel.OfficeLocationId); if (officeLocation != null) { officeLocation.OfficeAddress = officeLocationModel.OfficeAddress; officeLocation.TelephoneNo = officeLocationModel.TelephoneNo; officeLocation.Fax = officeLocationModel.Fax; officeLocation.Email = officeLocationModel.Email; officeLocation.Latitude = officeLocationModel.Latitude; officeLocation.Longitude = officeLocationModel.Longitude; officeLocation.City = officeLocationModel.City; _OfficeLocationService.UpdateOfficeLocation(officeLocation); TempData["ShowMessage"] = "success"; TempData["MessageBody"] = "Office Location successfully updated"; return(RedirectToAction("index")); } } else { TempData["ShowMessage"] = "error"; if (OfficeLocationFound.Email.Trim() == officeLocationModel.Email.Trim()) { TempData["MessageBody"] = officeLocationModel.Email + " is already exists."; } else if (OfficeLocationFound.Fax.Trim() == officeLocationModel.Fax.Trim()) { TempData["MessageBody"] = officeLocationModel.Fax + " is already exists."; } else if (OfficeLocationFound.TelephoneNo.Trim() == officeLocationModel.TelephoneNo.Trim()) { TempData["MessageBody"] = "This" + " " + officeLocationModel.TelephoneNo + " is already exists."; } else { TempData["MessageBody"] = "Please fill the required field with valid data"; } return(View(officeLocationModel)); } } return(View(officeLocationModel)); } catch (Exception ex) { CommonCls.ErrorLog(ex.ToString()); TempData["ShowMessage"] = "error"; TempData["MessageBody"] = ex.Message.ToString(); } //var errors = ModelState.Where(x => x.Value.Errors.Count > 0).Select(x => new { x.Key, x.Value.Errors }).ToArray(); //var modelStateErrors = this.ModelState.Keys.SelectMany(key => this.ModelState[key].Errors); return(View()); }