Example #1
0
        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);
        }
Example #2
0
        public IActionResult AddCenter(CenterDto centerDto)
        {
            var u = this.User;

            _centerService.AddCenter(centerDto);
            return(Ok());
        }
Example #3
0
        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"));
            }
        }
Example #4
0
        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);
            //}
        }
Example #5
0
        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);
        }
Example #6
0
        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();
        }
Example #7
0
        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);
        }
Example #8
0
        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);
        }
Example #9
0
 public IActionResult Put(CenterDto centerDto)
 {
     centerService.Update(centerDto);
     return(Ok(centerDto));
 }
Example #10
0
 public IActionResult PutByCenterOwner(string id, CenterDto centerDto)
 {
     centerService.Update(id, centerDto);
     return(Ok(centerDto));
 }
Example #11
0
        public IActionResult Post(CenterDto centerDto)
        {
            var result = centerService.Add(centerDto);

            return(Created("", result));
        }
Example #12
0
 public void AddCenter(CenterDto center)
 {
     _centerRepository.AddCenter(center.MapToDbModel());
 }