Example #1
0
        public GeneralResponse AddProvince(AddProvinceRequest request)
        {
            GeneralResponse response = new GeneralResponse();

            try
            {
                Province province = new Province();
                province.ID             = Guid.NewGuid();
                province.CreateDate     = PersianDateTime.Now;
                province.CreateEmployee = _employeeRepository.FindBy(request.EmployeeId);
                province.ProvinceName   = request.ProvinceName;
                province.RowVersion     = 1;
                //Validation
                if (province.GetBrokenRules().Count() > 0)
                {
                    foreach (BusinessRule businessRule in province.GetBrokenRules())
                    {
                        response.ErrorMessages.Add(businessRule.Rule);
                    }
                    return(response);
                }
                _provinceRepository.Add(province);
                _uow.Commit();
            }
            catch (Exception ex)
            {
                response.ErrorMessages.Add(ex.Message);
                if (ex.InnerException != null)
                {
                    response.ErrorMessages.Add(ex.InnerException.Message);
                }
            }
            return(response);
        }
Example #2
0
        public Province Add(Province Province)
        {
            var newProvince = _ProvinceRepository.Add(Province);

            _unitOfWork.Commit();
            return(newProvince);
        }
        public void CreateProvince(ProvinceViewModel provoinceVm)
        {
            var province  = Mapper.Map <ProvinceViewModel, Province>(provoinceVm);
            var districts = Mapper.Map <List <DistrictViewModel>, List <District> >(provoinceVm.Districts);
            var wards     = Mapper.Map <List <WardViewModel>, List <Ward> >(provoinceVm.Wards);
            var streets   = Mapper.Map <List <StreetViewModel>, List <Street> >(provoinceVm.Streets);

            //foreach (var district in districts)
            //{
            //    var product = _disctrictRepository.FindById(district.ProvinceId);
            //    //district. = product.Price;
            //}
            province.Districts = districts;
            province.Wards     = wards;
            province.Streets   = streets;
            _provinceRepository.Add(province);
        }
        /// <summary>
        /// The Save
        /// </summary>
        /// <param name="entity">The entity<see cref="Province"/></param>
        /// <returns>The <see cref="ServiceResult"/></returns>
        public ServiceResult Save(Province entity)
        {
            try
            {
                if (entity.Identifier == 0)
                {
                    _repository.Add(entity);
                }
                else
                {
                    _repository.Update(entity);
                }

                return(new ServiceResult(true));
            }
            catch (Exception ex)
            {
                return(new ServiceResult(false)
                {
                    Error = ex.ToString()
                });
            }
        }
Example #5
0
        public override async Task <int> HandleCommand(AddCommand request, CancellationToken cancellationToken)
        {
            if (request.Province == null || string.IsNullOrEmpty(request.Province.Code))
            {
                throw new BusinessException("AddWrongInformation");
            }

            var province = (await provinceQueries.Gets($"p.code = '{request.Province.Code}' and p.is_deleted = 0")).FirstOrDefault();

            if (province != null)
            {
                throw new BusinessException("Province.ExistedCode");
            }

            var country = await countryQueries.Get(request.Province.CountryId);

            if (country == null)
            {
                throw new BusinessException("Country.NotExisted");
            }

            if (request.Province.RegionId != null)
            {
                var region = await regionQueries.Get(request.Province.RegionId.Value);

                if (region == null || region.CountryId != request.Province.CountryId)
                {
                    throw new BusinessException("Region.NotExisted");
                }
            }

            request.Province = CreateBuild(request.Province, request.LoginSession);
            var rs = await provinceRepository.Add(request.Province);

            return(rs == 0 ? -1 : 0);
        }
Example #6
0
 public long Add(ProvinceDto dto)
 {
     return(_provinceRepository.Add(dto.ToEntity()));
 }
Example #7
0
        public void Add(ProvinceViewModel provinceVm)
        {
            var province = Mapper.Map <ProvinceViewModel, Province>(provinceVm);

            _provinceRepository.Add(province);
        }
Example #8
0
        public void AddProvince(ProvinceDTO province)
        {
            var provinceEF = province.MappingProvince();

            provinceRepository.Add(provinceEF);
        }
Example #9
0
 public void Insert(Province entity) => _provinceRepository.Add(entity);
 public async Task <ActionResult> Add(Province province) =>
 (ModelState.IsValid && await _repository.Add(province) != null) ? (ActionResult)Ok(province) : BadRequest();