public ApiResponseModel <MoviesType> Add([FromBody] AddRequestModel requestModel) { var responseModel = new ApiResponseModel <MoviesType>(); try { var record = new MoviesType(); record.Name = requestModel.Name; record.IsDeleted = false; var dbResult = _moviesTypeService.Add(record); if (dbResult > 0) { responseModel.Data = record; // oluşturulan entity bilgisinde id kolonu atanmış olur ve entity geri gönderiliyor responseModel.ResultStatusCode = ResultStatusCodeStatic.Success; responseModel.ResultStatusMessage = "Success"; } else { responseModel.ResultStatusCode = ResultStatusCodeStatic.Error; responseModel.ResultStatusMessage = "Could Not Be Saved"; } } catch (Exception ex) { responseModel.ResultStatusCode = ResultStatusCodeStatic.Error; responseModel.ResultStatusMessage = ex.Message; } return(responseModel); }
public ActionResult Add(Models.MoviesType.AddViewModel model) { if (!ModelState.IsValid) { //select lists return(View(model)); } Business.Models.MoviesType.MoviesType moviesType = new Business.Models.MoviesType.MoviesType(); moviesType.Name = model.Name; var apiResponseModel = _moviesTypeService.Add(SessionHelper.CurrentUser.UserToken, moviesType); if (apiResponseModel.ResultStatusCode == ResultStatusCodeStatic.Success) { return(RedirectToAction(nameof(MoviesTypeController.List))); } else { ViewBag.ErrorMessage = apiResponseModel.ResultStatusMessage != null ? apiResponseModel.ResultStatusMessage : "Not Saved"; return(View(model)); } }