Пример #1
0
        public async Task <IActionResult> Create([FromBody] VendorCreateViewModel input)
        {
            var user   = User.GetDetails();
            var data   = _mapper.Map <VendorCreateViewModel, Vendor>(input);
            var vendor = new Vendor(input.Name, input.ContactPerson, true, input.Status, input.ProprietorName, user.Id);

            vendor.SetContactDetailsAndIdentity(input.MobileNo, input.LandlineNo, input.PANNo, input.PANHolderName, input.AadharNo);
            vendor.SetVendorTypeAndStatus(input.VendorType, input.VendorStatus);
            vendor.AddVendorUsers(data.VendorUsers.ToList(), user.Id);
            if (await _unitOfWork.Vendors.AnyAsync(vendor))
            {
                return(BadRequest("Vendor Already Exists"));
            }

            _unitOfWork.Vendors.Add(vendor);
            await _unitOfWork.CompleteAsync(user.Id);

            return(Ok(vendor));
        }
Пример #2
0
        public async Task <IActionResult> InviteVendor([FromBody] VendorInvitationViewModel input)
        {
            var user             = User.GetDetails();
            var vendorInvitation = new Vendor(input.Name, input.VendorType, user.Id);
            var vendorUsers      = new List <VendorUser>()
            {
                new VendorUser(input.Email, " ", "")
            };

            vendorInvitation.AddVendorUsers(vendorUsers, user.Id);

            if (await _unitOfWork.Vendors.AnyAsync(vendorInvitation))
            {
                return(BadRequest("Vendor Already Exists."));
            }

            _unitOfWork.Vendors.Add(vendorInvitation);
            await _unitOfWork.CompleteAsync(user.Id);

            return(Ok(vendorInvitation));
        }