Exemple #1
0
        public async Task <ActionResult <VendorUserForGetDTO> > Post(VendorUserForAddDTO model)
        {
            if (await _vendorUserRepository.IsExistByPhone(model.Phone).ConfigureAwait(true))
            {
                return(Conflict(new ApiResponse(409, StringConcatenates.Exist("Phone", model.Phone))));
            }

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

            VendorUser vendorUser = _mapper.Map <VendorUser>(model);
            string     password   = SecurePassword.GeneratePassword(8);

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

            await _vendorUserRepository.AddAsync(vendorUser).ConfigureAwait(true);

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

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

            VendorUserForGetDTO vendorUserDto = _mapper.Map <VendorUserForGetDTO>(vendorUser);

            return(Ok(vendorUserDto));
        }
Exemple #2
0
        public async Task <ActionResult <CategoryForGetDTO> > Delete(int id)
        {
            if (!await _categoryRepository.IsExist(id).ConfigureAwait(true))
            {
                return(NotFound(new ApiResponse(404, StringConcatenates.NotExist("Category", id))));
            }

            if (await _vendorRepository.IsExistByCategory(id).ConfigureAwait(true))
            {
                return(Conflict(new ApiResponse(409, StringConcatenates.Exist(id, "vendors"))));
            }

            Category category = await _categoryRepository.GetAsync(id).ConfigureAwait(true);

            _categoryRepository.Remove(category);
            await _unitOfWork.CompleteAsync().ConfigureAwait(true);

            CategoryForGetDTO knwoningDto = _mapper.Map <CategoryForGetDTO>(category);

            return(Ok(knwoningDto));
        }
        public async Task <ActionResult <CustomerForGetDTO> > Put(int id, CustomerForEditDTO model)
        {
            if (id != model.Id)
            {
                return(BadRequest(new ApiResponse(400, StringConcatenates.NotEqualIds(id, model.Id))));
            }

            if (!await _customerRepository.IsExist(id).ConfigureAwait(true))
            {
                return(NotFound(new ApiResponse(404, StringConcatenates.NotExist("Customer", id))));
            }

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

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

            Customer oldCustomer = await _customerRepository.GetAsync(id).ConfigureAwait(true);

            Customer customer = _mapper.Map <Customer>(model);

            customer.PasswordHash = oldCustomer.PasswordHash;
            customer.PasswordSalt = oldCustomer.PasswordSalt;
            customer.IsBlocked    = oldCustomer.IsBlocked;
            customer.IsRandom     = oldCustomer.IsRandom;
            customer.PictureName  = oldCustomer.PictureName;

            _customerRepository.Edit(customer);
            await _unitOfWork.CompleteAsync().ConfigureAwait(true);

            CustomerForGetDTO customerDto = _mapper.Map <CustomerForGetDTO>(customer);

            return(Ok(customerDto));
        }
Exemple #4
0
        public async Task <ActionResult <VendorUserForGetDTO> > Put(int id, VendorUserForEditDTO model)
        {
            if (id != model.Id)
            {
                return(BadRequest(new ApiResponse(400, StringConcatenates.NotEqualIds(id, model.Id))));
            }

            if (!await _vendorUserRepository.IsExist(id).ConfigureAwait(true))
            {
                return(NotFound(new ApiResponse(404, StringConcatenates.NotExist("Vendor User", id))));
            }

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

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

            VendorUser oldVendorUser = await _vendorUserRepository.GetAsync(id).ConfigureAwait(true);

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

            vendorUser.PasswordHash = oldVendorUser.PasswordHash;
            vendorUser.PasswordSalt = oldVendorUser.PasswordSalt;
            vendorUser.VendorId     = oldVendorUser.VendorId;
            vendorUser.IsRandom     = oldVendorUser.IsRandom;

            _vendorUserRepository.Edit(vendorUser);
            await _unitOfWork.CompleteAsync().ConfigureAwait(true);

            VendorUserForGetDTO vendorUserDto = _mapper.Map <VendorUserForGetDTO>(vendorUser);

            return(Ok(vendorUserDto));
        }