Exemplo n.º 1
0
        public async Task <VendorDto> AddVendorAsync(AddVendorDto model, CancellationToken cancellationToken)
        {
            var vendor = _mapper.Map <Vendor>(model);

            vendor.SetInitialValues();
            await _vendorRepository.AddAsync(vendor, cancellationToken);

            return(_mapper.Map <VendorDto>(vendor));
        }
Exemplo n.º 2
0
        public async Task <int> AddAsync(VendorAddModel model)
        {
            var vendor = VendorFactory.Create(model, _userId);

            await _vendorRepository.AddAsync(vendor);

            await _unitOfWork.SaveChangesAsync();

            return(vendor.Id);
        }
        public async Task <long> AddAsyc(object obj)
        {
            var objModel = JObject.Parse(obj.ToString());

            var vendor = new Vendor();

            vendor = objModel.ToObject <Vendor>();

            return(await _vendorRepository.AddAsync(vendor));
        }
Exemplo n.º 4
0
        public async Task <ActionResult <VendorForGetDTO> > Post(VendorForAddDTO model)
        {
            if (await _vendorRepository.IsExist(model.Name, model.CategoryId).ConfigureAwait(true))
            {
                return(Conflict(new ApiResponse(409, StringConsts.EXISTED)));
            }

            if (await _vendorUserRepository.IsExistByPhone(model.VendorUser.Phone).ConfigureAwait(true))
            {
                return(Conflict(new ApiResponse(409, StringConcatenates.Exist("Phone", model.VendorUser.Phone))));
            }

            if (await _vendorUserRepository.IsExistByEmail(model.VendorUser.Email).ConfigureAwait(true))
            {
                return(Conflict(new ApiResponse(409, StringConcatenates.Exist("Email", model.VendorUser.Email))));
            }

            Vendor vendor = _mapper.Map <Vendor>(model);

            VendorUser vendorUser = _mapper.Map <VendorUser>(model.VendorUser);

            string password = SecurePassword.GeneratePassword(8);

            SecurePassword.CreatePasswordHash(password, out byte[] passwordHash, out byte[] passwordSalt);
            vendorUser.PasswordHash = passwordHash;
            vendorUser.PasswordSalt = passwordSalt;
            vendorUser.Role         = VendorUserRoleEnum.GroupAdmin;

            vendor.VendorUsers.Add(vendorUser);
            await _vendorRepository.AddAsync(vendor).ConfigureAwait(true);

            await _unitOfWork.CompleteAsync().ConfigureAwait(true);

            Email.Send("Momen", vendorUser.Email, "password", password);

            vendor = await _vendorRepository.GetAsync(vendor.Id).ConfigureAwait(true);

            VendorForGetDTO vendorDto = _mapper.Map <VendorForGetDTO>(vendor);

            return(Ok(vendorDto));
        }