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

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

            if (await _vendorRepository.IsExist(model.Id, model.Name, model.CategoryId).ConfigureAwait(true))
            {
                return(Conflict(new ApiResponse(409, StringConsts.EXISTED)));
            }

            Vendor oldVendor = await _vendorRepository.GetAsync(id).ConfigureAwait(true);

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

            vendor.LicenseName    = oldVendor.LicenseName;
            vendor.LogoName       = oldVendor.LogoName;
            vendor.PersonalIdName = oldVendor.PersonalIdName;

            _vendorRepository.Edit(vendor);
            await _unitOfWork.CompleteAsync().ConfigureAwait(true);

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

            return(Ok(vendorDto));
        }
        public async Task <ActionResult> UploadPersonalId(int id, [FromForm] VendorForPersonalIdDTO model)
        {
            if (id != model.Id)
            {
                return(BadRequest(new ApiResponse(400, StringConcatenates.NotEqualIds(id, model.Id))));
            }

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

            FileOperations.WriteFile($"Vendors/{model.Id}/PersonalId", model.PersonalId);

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

            vendor.PersonalIdName = model.PersonalId.FileName;

            _vendorRepository.Edit(vendor);
            await _unitOfWork.CompleteAsync().ConfigureAwait(true);

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

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

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

            if (await _contractRepository.IsExist(model.Id, model.Name).ConfigureAwait(true))
            {
                return(Conflict(new ApiResponse(409, StringConsts.EXISTED)));
            }

            Contract oldContract = await _contractRepository.GetAsync(id).ConfigureAwait(true);

            Contract contract = _mapper.Map <Contract>(model);

            contract.PdfName = oldContract.PdfName;
            _contractRepository.Edit(contract);
            await _unitOfWork.CompleteAsync().ConfigureAwait(true);

            ContractForGetDTO contractDto = _mapper.Map <ContractForGetDTO>(contract);

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

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

            if (await _categoryRepository.IsExist(model.Id, model.Name).ConfigureAwait(true))
            {
                return(Conflict(new ApiResponse(409, StringConsts.EXISTED)));
            }

            Category category = _mapper.Map <Category>(model);

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

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

            return(Ok(categoryDto));
        }
        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 #6
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));
        }
Exemple #7
0
        public async Task <ActionResult> ChangePassword(int id, VendorUserForChangePasswordDTO 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))));
            }

            VendorUser vendorUser = await _vendorUserRepository.GetAsync(model.Id).ConfigureAwait(true);

            SecurePassword.CreatePasswordHash(model.Password, out byte[] passwordHash, out byte[] passwordSalt);
            vendorUser.PasswordHash = passwordHash;
            vendorUser.PasswordSalt = passwordSalt;
            vendorUser.IsRandom     = false;

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

            return(Ok());
        }
        public async Task <ActionResult> UploadPicture(int id, [FromForm] CustomerForPictureDTO 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("Customers", id))));
            }

            FileOperations.WriteFile($"Customers/{model.Id}", model.Picture);

            Customer customer = await _customerRepository.GetAsync(model.Id).ConfigureAwait(true);

            customer.PictureName = model.Picture.FileName;
            _customerRepository.Edit(customer);
            await _unitOfWork.CompleteAsync().ConfigureAwait(true);

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

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

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

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

            vendor.ContractId = model.ContractId;
            vendor.Status     = VendorStatusEnum.WaitingForAccept;

            _vendorRepository.Edit(vendor);
            await _unitOfWork.CompleteAsync().ConfigureAwait(true);

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

            return(Ok(vendorDto));
        }
Exemple #10
0
        public async Task <ActionResult> UploadPdf(int id, [FromForm] ContractForFileDTO model)
        {
            if (id != model.Id)
            {
                return(BadRequest(new ApiResponse(400, StringConcatenates.NotEqualIds(id, model.Id))));
            }

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

            FileOperations.WriteFile($"Contracts/{model.Id}", model.Pdf);

            Contract contract = await _contractRepository.GetAsync(model.Id).ConfigureAwait(true);

            contract.PdfName = model.Pdf.FileName;
            _contractRepository.Edit(contract);
            await _unitOfWork.CompleteAsync().ConfigureAwait(true);

            ContractForGetDTO contractDto = _mapper.Map <ContractForGetDTO>(contract);

            return(Ok(contractDto));
        }