public async Task <ResultViewModel> RegisterUserAsync(RegisterRequestModel model, CancellationToken ct = default)
        {
            User user = _mapper.Map <User>(model);

            _userRepository.Add(user);
            user.Agency.Owner = user;

            user.Employee.Agency = user.Agency;
            _agencyRepository.Add(user.Agency);

            await _unitOfWork.SaveChangesAsync(ct);

            return(new ResultViewModel());
        }
Beispiel #2
0
        public async Task RegisterUserAsync(RegisterRequestModel model, CancellationToken ct)
        {
            User user = _mapper.Map <User>(model);

            _userRepository.Add(user);
            user.Agency.Owner = user;

            user.Employee.Agency = user.Agency;
            _agencyRepository.Add(user.Agency);



            await _unitOfWork.SaveChangesAsync();
        }
Beispiel #3
0
        public async Task <ActionResult <AgencyDto> > CreateAgency(AgencyForCreationDto agencyForCreationDto)
        {
            var agencyEntity = _mapper.Map <Agency>(agencyForCreationDto);

            //add payment record
            var receiptType = await _systemRepo.GetReceiptType(agencyForCreationDto.ReceiptTypeId);

            if (receiptType == null)
            {
                return(BadRequest("Could not find receiptType."));
            }

            agencyEntity.Payment = new Payment {
                AmountBalance        = 0,
                CurrentReceiptNumber = 0,
                MinUnitThreshold     = (agencyForCreationDto.MinUnitThreshold > 0 ? agencyForCreationDto.MinUnitThreshold : 10),
                Unit               = 0,
                ReceiptType        = receiptType.Type,
                UnitPerReceiptType = receiptType.UnitPerType
            };

            _AgenciesRepo.Add(agencyEntity);

            if (await _AgenciesRepo.Save())
            {
                var AgencyToReturn = _mapper.Map <AgencyDto>(agencyEntity);
                return(CreatedAtRoute("GetAgency", new { AgencyToReturn.Id }, AgencyToReturn));
            }

            throw new Exception("Creating Agency failed on save");
        }
        public IActionResult Create(Agency agency)
        {
            try
            {
                _agencyRepository.Add(agency);
                return(RedirectToAction("Index"));
            }
            catch
            {
                ViewBag.Nationalities               = _personRepository.Nationalities;
                ViewBag.AddressTypes                = _personRepository.AddressTypes;
                ViewBag.PhoneTypes                  = _personRepository.PhoneTypes;
                ViewBag.EmailTypes                  = _personRepository.EmailTypes;
                ViewBag.SocialTypes                 = _personRepository.SocialTypes;
                ViewBag.OTTTypes                    = _personRepository.OTTTypes;
                ViewBag.BankAccountTypes            = _personRepository.BankAccountTypes;
                ViewBag.BankCardTypes               = _personRepository.BankCardTypes;
                ViewBag.Wards                       = _personRepository.Wards;
                ViewBag.DistrictPlaces              = _personRepository.DistrictPlaces;
                ViewBag.Provinces                   = _personRepository.Provinces;
                ViewBag.Representatives             = _personRepository.Representatives;
                ViewBag.Employees                   = _personRepository.Employees;
                ViewBag.AgencyGroups                = _agencyRepository.AgencyGroups;
                ViewBag.AgencyBusinesses            = _agencyRepository.AgencyBusinesses;
                ViewBag.CurrencyTypes               = _agencyRepository.CurrencyTypes;
                ViewBag.PaymentTypes                = _agencyRepository.PaymentTypes;
                ViewBag.PaymentTermTypes            = _agencyRepository.PaymentTermTypes;
                ViewBag.AgencyDiscountTypes         = _agencyRepository.AgencyDiscountTypes;
                ViewBag.PickupTypes                 = _agencyRepository.PickupTypes;
                ViewBag.AgencyDiscountCustomerTypes = _agencyRepository.AgencyDiscountCustomerTypes;

                return(View(agency));
            }
        }
Beispiel #5
0
        public GeneralResponse AddAgency(AddAgencyRequest request, Guid createEmployeeID)
        {
            GeneralResponse response = new GeneralResponse();

            try
            {
                Agency agency = new Agency();
                agency.ID             = Guid.NewGuid();
                agency.CreateDate     = PersianDateTime.Now;
                agency.CreateEmployee = _employeeRepository.FindBy(createEmployeeID);
                agency.AgencyName     = request.AgencyName;
                agency.ManagerName    = request.ManagerName;
                agency.Phone1         = request.Phone1;
                agency.Phone2         = request.Phone2;
                agency.Mobile         = request.Mobile;
                agency.Address        = request.Address;
                agency.Note           = request.Note;
                agency.Discontinued   = request.Discontinued;
                agency.SortOrder      = GetMaxSortOrder();
                agency.RowVersion     = 1;

                // Validation
                if (agency.GetBrokenRules().Count() > 0)
                {
                    foreach (BusinessRule businessRule in agency.GetBrokenRules())
                    {
                        response.ErrorMessages.Add(businessRule.Rule);
                    }
                    return(response);
                }

                _agencyRepository.Add(agency);
                _uow.Commit();
            }
            catch (Exception ex)
            {
                response.ErrorMessages.Add(ex.Message);
                if (ex.InnerException != null)
                {
                    response.ErrorMessages.Add(ex.InnerException.Message);
                }
                return(response);
            }

            return(response);
        }