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));
        }
Example #2
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> 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));
        }
Example #4
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));
        }
Example #5
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));
        }
Example #6
0
        public async Task <ActionResult <IReadOnlyList <VendorUserForGetDTO> > > GetByVendor(int vendorId)
        {
            if (!await _vendorRepository.IsExist(vendorId).ConfigureAwait(true))
            {
                return(NotFound(new ApiResponse(404, StringConcatenates.NotExist("Vendor", vendorId))));
            }

            List <VendorUserForGetDTO> vendorUsers = _mapper.Map <List <VendorUserForGetDTO> >(await _vendorUserRepository.GetByVendorAsync(vendorId).ConfigureAwait(true));

            return(Ok(vendorUsers));
        }
        public async Task <ActionResult <CustomerForGetDTO> > Get(int id)
        {
            if (!await _customerRepository.IsExist(id).ConfigureAwait(true))
            {
                return(NotFound(new ApiResponse(404, StringConcatenates.NotExist("Customer", id))));
            }

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

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

            return(Ok(customerDto));
        }
Example #8
0
        public async Task <ActionResult <VendorUserForGetDTO> > GetAdmin(int vendorId)
        {
            if (!await _vendorRepository.IsExist(vendorId).ConfigureAwait(true))
            {
                return(NotFound(new ApiResponse(404, StringConcatenates.NotExist("Vendor", vendorId))));
            }

            VendorUser vendorUser = await _vendorUserRepository.GetAdminAsync(vendorId).ConfigureAwait(true);

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

            return(Ok(vendorUserDto));
        }
Example #9
0
        public async Task <ActionResult <ContractForGetDTO> > Get(int id)
        {
            if (!await _contractRepository.IsExist(id).ConfigureAwait(true))
            {
                return(NotFound(new ApiResponse(404, StringConcatenates.NotExist("Contract", id))));
            }

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

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

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

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

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

            return(Ok(categoryDto));
        }
Example #11
0
        public async Task <ActionResult <VendorUserForGetDTO> > Delete(int id)
        {
            if (!await _vendorUserRepository.IsExist(id).ConfigureAwait(true))
            {
                return(NotFound(new ApiResponse(404, StringConcatenates.NotExist("Vendor User", id))));
            }

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

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

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

            return(Ok(vendorUserDto));
        }
        public async Task <ActionResult <CustomerForGetDTO> > Delete(int id)
        {
            if (!await _customerRepository.IsExist(id).ConfigureAwait(true))
            {
                return(NotFound(new ApiResponse(404, StringConcatenates.NotExist("Customer", id))));
            }

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

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

            FolderOperations.DeleteFolder($"Customers/{id}");

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

            return(Ok(customerDto));
        }
        public async Task <ActionResult> Unblock(int id)
        {
            if (!await _customerRepository.IsExist(id).ConfigureAwait(true))
            {
                return(NotFound(new ApiResponse(404, StringConcatenates.NotExist("Customer", id))));
            }

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

            customer.IsBlocked = false;

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

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

            return(Ok(customerDto));
        }
Example #14
0
        public async Task <ActionResult <VendorPictureForGetDTO> > Delete(int id)
        {
            if (!await _vendorPictureRepository.IsExist(id).ConfigureAwait(true))
            {
                return(NotFound(new ApiResponse(404, StringConcatenates.NotExist("VendorPicture", id))));
            }

            VendorPicture vendorPicture = await _vendorPictureRepository.GetAsync(id).ConfigureAwait(true);

            _vendorPictureRepository.Remove(vendorPicture);
            await _unitOfWork.CompleteAsync().ConfigureAwait(true);

            FileOperations.DeleteFile($"Vendors/{vendorPicture.VendorId}/Pictures", vendorPicture.PictureName);

            VendorPictureForGetDTO vendorPictureDto = _mapper.Map <VendorPictureForGetDTO>(vendorPicture);

            return(Ok(vendorPictureDto));
        }
Example #15
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));
        }
Example #17
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));
        }
Example #18
0
        public async Task <ActionResult> ResetPassword(int id)
        {
            if (!await _vendorUserRepository.IsExist(id).ConfigureAwait(true))
            {
                return(NotFound(new ApiResponse(404, StringConcatenates.NotExist("Vendor User", id))));
            }

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

            string password = SecurePassword.GeneratePassword(8);

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

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

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

            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));
        }
Example #20
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));
        }
Example #21
0
        public async Task <ActionResult <VendorRejectForGetDTO> > Post(VendorRejectForAddDTO model)
        {
            if (!await _vendorRepository.IsExist(model.VendorId).ConfigureAwait(true))
            {
                return(NotFound(new ApiResponse(404, StringConcatenates.NotExist("Vendor", model.VendorId))));
            }

            VendorReject vendorReject = _mapper.Map <VendorReject>(model);

            await _vendorRejectRepository.AddAsync(vendorReject).ConfigureAwait(true);

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

            vendor.Status = VendorStatusEnum.Rejected;
            _vendorRepository.Edit(vendor);

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



            VendorRejectForGetDTO vendorRejectDto = _mapper.Map <VendorRejectForGetDTO>(vendorReject);

            return(Ok(vendorRejectDto));
        }
Example #22
0
        public async Task <ActionResult <IReadOnlyList <VendorPictureForGetDTO> > > Post([FromForm] VendorPictureForAddDTO model)
        {
            if (!await _vendorRepository.IsExist(model.VendorId).ConfigureAwait(true))
            {
                return(NotFound(new ApiResponse(404, StringConcatenates.NotExist("Vendor", model.VendorId))));
            }

            foreach (var file in model.Pictures)
            {
                FileOperations.WriteFile($"Vendors/{model.VendorId}/Pictures", file);

                VendorPicture vendorPicture = new VendorPicture
                {
                    VendorId    = model.VendorId,
                    PictureName = file.FileName
                };
                await _vendorPictureRepository.AddAsync(vendorPicture).ConfigureAwait(true);
            }
            await _unitOfWork.CompleteAsync().ConfigureAwait(true);

            List <VendorPictureForGetDTO> vendorPictures = _mapper.Map <List <VendorPictureForGetDTO> >(await _vendorPictureRepository.GetByVendorAsync(model.VendorId).ConfigureAwait(true));

            return(Ok(vendorPictures));
        }
        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));
        }
Example #24
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());
        }