public ActionResult Edit([Bind(Include = "LocationId,Name,Description,CurrentPageNo")] LocationModel LocationModel) { UserPermissionAction("Location", RoleAction.view.ToString()); CheckPermission(); try { TempData["ShowMessage"] = "error"; TempData["MessageBody"] = "Please fill the required field with valid data"; if (ModelState.IsValid) { //var Location = form["LocationLists"].ToString(); var IsParentAllReadyContainLocationName = _LocationService.GetLocations().Where(c => c.LocationId != LocationModel.LocationId).Select(c => c.Title); if (IsParentAllReadyContainLocationName.Contains(LocationModel.Title.Trim())) { TempData["ShowMessage"] = "error"; TempData["MessageBody"] = " Location name is already exist."; return(RedirectToAction("Edit")); } Location LocationFound = _LocationService.GetLocations().Where(x => x.Title == LocationModel.Title && x.LocationId != LocationModel.LocationId).FirstOrDefault(); Mapper.CreateMap <Friendlier.Models.LocationModel, Friendlier.Entity.Location>(); Friendlier.Entity.Location Locations = Mapper.Map <Friendlier.Models.LocationModel, Friendlier.Entity.Location>(LocationModel); if (LocationFound == null) { //Locations.IsActive = true; _LocationService.UpdateLocation(Locations); TempData["ShowMessage"] = "success"; TempData["MessageBody"] = " Location update successfully."; return(RedirectToAction("Index", new { CurrentPageNo = LocationModel.CurrentPageNo })); // end Update CompanyEquipments } else { TempData["ShowMessage"] = "error"; if (LocationFound.Title.Trim().ToLower() == LocationModel.Title.Trim().ToLower()) //Check User Name { TempData["MessageBody"] = LocationFound.Title + " already exist."; } else { TempData["MessageBody"] = "Some unknown problem occured while proccessing save operation on "; } } } } catch (Exception ex) { string ErrorMsg = ex.Message.ToString();// ErrorLogging.LogError(ex); } ViewBag.Location = new SelectList(_LocationService.GetLocations(), "LocationId", "Name", LocationModel.LocationId); return(View(LocationModel)); }
public HttpResponseMessage SaveLocation([FromBody] LocationModel LocationModel) { int locationId = 0; try { if (LocationModel.CustomerId == 0) { return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "Customer Id is blank"), Configuration.Formatters.JsonFormatter)); } if (LocationModel.Title == null || LocationModel.Title == "") { return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "Title is blank"), Configuration.Formatters.JsonFormatter)); } if (LocationModel.Description == null || LocationModel.Description == "") { return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "Description is blank"), Configuration.Formatters.JsonFormatter)); } //if (LocationModel.ContactInfo == null && LocationModel.ContactInfo == "") //{ // return Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "ContactInfo is blank"), Configuration.Formatters.JsonFormatter); //} if (LocationModel.Street == null || LocationModel.Street == "") { return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "Street is blank"), Configuration.Formatters.JsonFormatter)); } if (LocationModel.City == null || LocationModel.City == "") { return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "City is blank"), Configuration.Formatters.JsonFormatter)); } if (LocationModel.State == null || LocationModel.State == "") { return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "State is blank"), Configuration.Formatters.JsonFormatter)); } if (LocationModel.Country == null || LocationModel.Country == "") { return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "Country is blank"), Configuration.Formatters.JsonFormatter)); } if (LocationModel.CategoryIds == null || LocationModel.CategoryIds == "") { return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "CategoryIds is blank"), Configuration.Formatters.JsonFormatter)); } if (LocationModel.Ratings == 0) { return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "Ratings is blank"), Configuration.Formatters.JsonFormatter)); } var customer = _CustomerService.GetCustomers().Where(c => c.CustomerId == LocationModel.CustomerId && c.IsActive == true).FirstOrDefault(); if (customer != null) { var street = _LocationService.GetLocations().Where(l => l.Street.ToLower() == LocationModel.Street.ToLower()).Distinct().ToList(); if (street.Count() > 0) { var entity1 = street.Where(l => l.City.ToLower() == LocationModel.City.ToLower()).Distinct().ToList(); if (entity1.Count() > 0) { var entity2 = street.Where(l => l.State.ToLower() == LocationModel.State.ToLower()).Distinct().ToList(); if (entity2.Count() > 0) { var entity3 = street.Where(l => l.Country.ToLower() == LocationModel.Country.ToLower()).Distinct().ToList(); if (entity3.Count() > 0) { return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "this location already exists."), Configuration.Formatters.JsonFormatter)); } } } } string[] categoryIds = LocationModel.CategoryIds.Split(','); List <int> CatIds = _CategoryService.GetCategories().Select(c => c.CategoryId).ToList(); // var CatIds = Categories.Select(c => c.CategoryId); List <string> Ids = CatIds.ConvertAll <string>(x => x.ToString()); bool isMatched = true; foreach (var item in categoryIds) { if (!Ids.Contains(item)) { isMatched = false; } } IEnumerable <string> difference = Ids.Except(categoryIds); if (isMatched) { Mapper.CreateMap <Friendlier.Models.LocationModel, Friendlier.Entity.Location>(); Friendlier.Entity.Location location = Mapper.Map <Friendlier.Models.LocationModel, Friendlier.Entity.Location>(LocationModel); //string[] contactDetails = LocationModel.ContactInfo.Split('|'); //location.EmailId = contactDetails[1]; //location.MobileNo = contactDetails[0]; location.EmailId = LocationModel.EmailId; location.MobileNo = LocationModel.MobileNo; location.CategoryIds = LocationModel.CategoryIds; location.IsApproved = false; location.Status = EnumValue.GetEnumDescription(EnumValue.LocationStatus.New); _LocationService.InsertLocation(location); locationId = location.LocationId; if (LocationModel.Tags != null && LocationModel.Tags != "") { string[] tagList = LocationModel.Tags.Split(','); foreach (var tag in tagList) { LocationTag locationTag = new LocationTag(); locationTag.LocationId = locationId; locationTag.Tag = tag; _LocationTagService.InsertLocationTag(locationTag); } } Mapper.CreateMap <Location, LocationResponseModel>(); LocationResponseModel model = Mapper.Map <Location, LocationResponseModel>(location); model.Tags = LocationModel.Tags; SendMailToAdmin(customer.FirstName, model.Title, model.Street + " " + model.City + " " + model.State + " " + model.Country); //model.ContactInfo = location.MobileNo + "|" + location.EmailId; return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("success", model), Configuration.Formatters.JsonFormatter)); } else { return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "Category id is wrong."), Configuration.Formatters.JsonFormatter)); } } else { return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "Customer id is wrong."), Configuration.Formatters.JsonFormatter)); } } catch (Exception ex) { string ErrorMsg = ex.Message.ToString(); ErrorLogging.LogError(ex); return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "Please try again."), Configuration.Formatters.JsonFormatter)); } }