public async Task <ResponseDto <int> > SaveAsync(CenterDto dto) { ResponseDto <int> responseDto = new ResponseDto <int>(); if (dto.Id > 0) { //Edit var entity = await GetByIdAsync(dto.Id); mapper.Map(dto, entity, typeof(CenterDto), typeof(Center)); Update(entity); responseDto.StatusCode = Core.Enums.StatusCode.Updated; } else { //New var entity = mapper.Map <Center>(dto); AddAsync(entity); responseDto.StatusCode = Core.Enums.StatusCode.OK; } responseDto.Data = await context.SaveChangesAsync(); if (responseDto.Data == 0) { responseDto.StatusCode = Core.Enums.StatusCode.SaveFailed; } return(responseDto); }
public IActionResult AddCenter(CenterDto centerDto) { var u = this.User; _centerService.AddCenter(centerDto); return(Ok()); }
public async Task <IActionResult> SaveAsync(CenterDto dto) { try { if (ModelState.IsValid) { var response = await centerService.SaveAsync(dto); if (response.StatusCode == Core.Enums.StatusCode.OK || response.StatusCode == Core.Enums.StatusCode.Updated) { TempData["Success"] = Resource.SavedSuccessfully; return(RedirectToAction("Index", new { id = response.Data })); } else { TempData["Error"] = Resource.SaveFailed; } } return(View(dto)); } catch { return(RedirectToAction("E500", "Error")); } }
private void centerValidator(CenterDto centerDto) { if (centerDto.CenterType == CenterType.Null || !centerDto.CenterType.IsDefined()) { throw new CenterException(CenterExceptionRole.InvalidType); } if (centerDto.DeliveryType == DeliveryType.Null || !centerDto.DeliveryType.IsDefined()) { throw new CenterException(CenterExceptionRole.InvalidDelivery); } if (string.IsNullOrEmpty(centerDto.Title) || string.IsNullOrWhiteSpace(centerDto.Title)) { throw new CenterException(CenterExceptionRole.InvalidTitle); } if (string.IsNullOrEmpty(centerDto.CityId) || !centerDto.CityId.IsValidGuid() || !addressService.IsCityExistsAndActive(centerDto.CityId)) { throw new AddressException(AddressExceptionRole.NotExistsOrDeactived); } //if (string.IsNullOrEmpty(centerDto.OwnerId) || // !centerDto.OwnerId.IsValidGuid() || // !addressService.IsCityExistsAndActive(centerDto.CityId)) //{ // throw new AddressException(AddressExceptionRole.NotExistsOrDeactived); //} }
public CenterDto Update(CenterDto centerDto) { centerValidator(centerDto); var center = centerFatory.CreateEntity(centerDto); unitOfWork.CenterRepository.Update(center); unitOfWork.SaveChanges(); var updatedDto = centerFatory.CreateDto(center); return(updatedDto); }
public CenterDto Update(string id, CenterDto centerDto) { if (!id.IsValidGuid()) { throw new EntityNotFoundException(typeof(CenterDto), id); } var centerForCheck = Get(id); //if (centerForCheck.) //{ //} throw new NotImplementedException(); }
public CenterDto Add(CenterDto centerDto) { centerValidator(centerDto); var center = centerFatory.CreateEntity(centerDto); unitOfWork.CenterRepository.Add(center); unitOfWork.SaveChanges(); var province = addressService.GetProvince(center.City.ProvinceId.ToString()); center.City.Province = new Province() { Id = province.Id.ToGuid(), Name = province.Name }; var addedDto = centerFatory.CreateDto(center); return(addedDto); }
public static Center MapToDbModel(this CenterDto centerDto) { var center = new Center { Name = centerDto.Name, UserId = centerDto.UserId, ContractExpireTime = centerDto.ContractExpireTime }; if (centerDto.Id != null) { center.Id = centerDto.Id.Value; } if (centerDto.CreationDate != null) { center.CreationDate = centerDto.CreationDate.Value; } return(center); }
public IActionResult Put(CenterDto centerDto) { centerService.Update(centerDto); return(Ok(centerDto)); }
public IActionResult PutByCenterOwner(string id, CenterDto centerDto) { centerService.Update(id, centerDto); return(Ok(centerDto)); }
public IActionResult Post(CenterDto centerDto) { var result = centerService.Add(centerDto); return(Created("", result)); }
public void AddCenter(CenterDto center) { _centerRepository.AddCenter(center.MapToDbModel()); }