public int?AddServices(OurServicesViewModel servicesViewModel) { Service model = _mapper.Map <Service>(servicesViewModel); model.IsActive = true; dbContext.services.Add(model); var result = this.dbContext.SaveChanges(); return(result); }
public ActionResult Edit(OurServicesViewModel ourServicesViewModel, HttpPostedFileBase files, string submit) { if (ModelState.IsValid) { if (ourServicesViewModel != null && submit == "Save") { ourServicesViewModel.DateCreated = ourServicesViewModel.DateCreated; ourServicesViewModel.DateModified = DateTime.UtcNow; if (files != null) { // Delete exiting file // System.IO.File.Delete(Path.Combine(Server.MapPath("~/Images/Category/"), serviceViewModel.Image)); // Save new file var fileName = Path.GetFileName(files.FileName); var path = Path.Combine(Server.MapPath("~/UploadFiles/OurServices/"), fileName); files.SaveAs(path); ourServicesViewModel.Image = fileName; } var service = Mapper.Map <OurServicesViewModel, OurService>(ourServicesViewModel); _ourServicesService.Edit(service); AddMessage(this, "", "Record has been modified Successfully", MessageType.Success); return(RedirectToAction("Index", "OurService")); } if (ourServicesViewModel != null && submit == "SaveAndContinue") { ourServicesViewModel.DateCreated = ourServicesViewModel.DateCreated; ourServicesViewModel.DateModified = DateTime.UtcNow; if (files != null) { // Delete exiting file // System.IO.File.Delete(Path.Combine(Server.MapPath("~/Images/Category/"), serviceViewModel.Image)); // Save new file var fileName = Path.GetFileName(files.FileName); var path = Path.Combine(Server.MapPath("~/UploadFiles/OurServices/"), fileName); files.SaveAs(path); ourServicesViewModel.Image = fileName; } var service = Mapper.Map <OurServicesViewModel, OurService>(ourServicesViewModel); _ourServicesService.Edit(service); var id = service.Id; AddMessage(this, "", "Record has been modified successfully", MessageType.Success); return(RedirectToAction("Edit", new { id = id })); } } return(View(ourServicesViewModel)); }
public ActionResult Create(OurServicesViewModel ourServicesViewModel, IEnumerable <HttpPostedFileBase> files, string submit) { if (ModelState.IsValid) { if (ourServicesViewModel != null && submit == "Save") { ourServicesViewModel.DateCreated = DateTime.UtcNow; ourServicesViewModel.DateModified = DateTime.UtcNow; foreach (var file in files) { //Some browsers send file names with a full path. You only care about the file name. var fileName = Path.GetFileName(file.FileName); var destinationPath = Path.Combine(Server.MapPath("~/UploadFiles/OurServices/"), fileName); ourServicesViewModel.Image = fileName; file.SaveAs(destinationPath); } var ourService = Mapper.Map <OurServicesViewModel, OurService>(ourServicesViewModel); _ourServicesService.Add(ourService); AddMessage(this, "", "Record has Added Successfully", MessageType.Success); return(RedirectToAction("Index", "OurService")); } if (ourServicesViewModel != null && submit == "SaveAndContinue") { ourServicesViewModel.DateCreated = DateTime.UtcNow; ourServicesViewModel.DateModified = DateTime.UtcNow; foreach (var file in files) { //Some browsers send file names with a full path. You only care about the file name. var fileName = Path.GetFileName(file.FileName); var destinationPath = Path.Combine(Server.MapPath("~/UploadFiles/OurServices/"), fileName); ourServicesViewModel.Image = fileName; file.SaveAs(destinationPath); } var ourService = Mapper.Map <OurServicesViewModel, OurService>(ourServicesViewModel); _ourServicesService.Add(ourService); AddMessage(this, "", "Record has Added Successfully", MessageType.Success); ModelState.Clear(); return(View()); } } return(View(ourServicesViewModel)); }
public IActionResult AddService(OurServicesViewModel servicesViewModel) { try { int?response = this._ouservices.AddServices(servicesViewModel); if (response == null) { return(Ok(new BaseViewModel { ResponseMessage = ResponseMessages.NoRecordFound, StatusCode = ApiResponseCode.NotFound.GetResponseCode() })); } else if (response == 0) { return(Ok(new BaseViewModel { ResponseMessage = ResponseMessages.UnprocessableEntity, StatusCode = ApiResponseCode.UnprocessableEntity.GetResponseCode() })); } else { return(Ok(new BaseViewModel { ResponseMessage = ResponseMessages.Success, StatusCode = ApiResponseCode.OK.GetResponseCode() })); } } catch (Exception) { return(Ok(new BaseViewModel { ResponseMessage = ResponseMessages.ServerError, StatusCode = ApiResponseCode.InternalServerError.GetResponseCode() })); } }
public ActionResult Create(OurServicesViewModel ourServicesViewModel) { ourServicesViewModel.ShowHideImage = false; return(View(ourServicesViewModel)); }