public async Task <IActionResult> Create(CategoryCityResource resource) { var response = new SingleModelResponse <CategoryCityResource>(); if (resource == null) { response.DidError = true; response.ErrorMessage = ResponseMessageConstants.NotFound; return(response.ToHttpResponse()); } try { var entity = new CategoryCity(); _mapper.Map(resource, entity); var entityAdded = await _cateBookingRepository.AddAsync(entity); response.Model = _mapper.Map(entityAdded, resource); response.Message = ResponseMessageConstants.Success; } catch (Exception ex) { response.DidError = true; response.ErrorMessage = ex.ToString(); _logger.LogError(ex.InnerException.ToString()); } return(response.ToHttpResponse()); }
public async Task <IActionResult> Update(CategoryCityViewModel model, string saveCommand = null) { if (!ModelState.IsValid) { return(View("CategoryCityForm", model)); } var entity = new CategoryCity(); _mapper.Map(model, entity); var response = await HttpRequestFactory.Put(Constants.BaseApiUrl + "CategoryCity/" + model.Id, entity); var outmodel = response.ContentAsType <SingleModelResponse <CategoryCity> >(); if (outmodel.DidError || !response.IsSuccessStatusCode) { ViewBag.ErrorMsg = outmodel.ErrorMessage ?? response.ReasonPhrase; return(View("CategoryCityForm", model)); } AlertShow(); if (saveCommand != Constants.SaveContinute) { return(RedirectToAction("Index")); } model = _mapper.Map(outmodel.Model, model); return(RedirectToAction("Edit", new { id = model.Id })); }
public async Task <IActionResult> GetAsync(int id) { var response = new SingleModelResponse <CategoryCity>(); try { var entity = await _cateBookingRepository.Query().FirstOrDefaultAsync(x => x.Id == id); if (entity == null) { response.DidError = true; response.ErrorMessage = ResponseMessageConstants.NotFound; return(response.ToHttpResponse()); } var resource = new CategoryCity(); _mapper.Map(entity, resource); response.Model = resource; } catch (Exception ex) { response.DidError = true; response.ErrorMessage = ex.Message; _logger.LogError(ex.InnerException.ToString()); } return(response.ToHttpResponse()); }