public async Task <ActionResult> EditSubCategory(Guid id, EditSubCategoryViewModel request) { if (!ModelState.IsValid) { Alert("Invalid Request", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime)); return(View()); } if (!id.Equals(request.Id)) { Alert("Invalid Request", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime)); return(View()); } try { var subCategoryEditRequest = new UpdateSubCategoryRequest { Id = request.Id, Name = request.Name, Description = request.Description, CategoryId = request.CategoryId }; var result = await _subCategoryService.Update(id, subCategoryEditRequest); if (!result.Success) { Alert($"Error: {result.Message}", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime)); return(View()); } Alert($"Sub Category Updated Successfully", NotificationType.success, Int32.Parse(_appConfig.Value.NotificationDisplayTime)); return(RedirectToAction(nameof(SubCategories), new { id = request.CategoryId })); } catch { Alert($"Error Occurred While processing the request", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime)); return(View()); } }
public async Task <IActionResult> Update([FromRoute] Int32 id, [FromBody] UpdateSubCategoryRequest SubCategoryRequst) { var SubCategory = new SubCategory { Id = id, CategoryId = SubCategoryRequst.CategoryId, ArabicName = SubCategoryRequst.ArabicName, EnglishName = SubCategoryRequst.EnglishName, ImgUrl = SubCategoryRequst.ImgUrl, Status = SubCategoryRequst.Status }; var status = await _SubCategoryService.UpdateSubCategoryAsync(SubCategory); if (status == -1) { return(Conflict(new ErrorResponse { message = "Dublicate Entry", status = Conflict().StatusCode })); } if (status == 1) { return(Ok(SubCategory)); } return(NotFound(new ErrorResponse { message = "Not Found", status = NotFound().StatusCode })); }
public async Task <ServiceResponse <SubCategory> > Update(Guid id, UpdateSubCategoryRequest request) { try { var result = await _baseRepository.GetById(id); if (result == null) { return(new ServiceResponse <SubCategory>($"The requested Category could not be found")); } result.Name = request.Name; result.Description = request.Description; result.LastUpdated = DateTime.Now; await _baseRepository.Update(id, result); return(new ServiceResponse <SubCategory>(result)); } catch (Exception ex) { return(new ServiceResponse <SubCategory>($"An Error Occured While Updating The Category. {ex.Message}")); } }