Example #1
0
        public ResponseMessage CreateVendor(AddVendor vendor)
        {
            ResponseMessage responseMessage = new ResponseMessage();

            responseMessage = _vendorRepository.CreateVendor(vendor);
            return(responseMessage);
        }
Example #2
0
        public ResponseMessage UpdateVendor(AddVendor vendor, int id)
        {
            ResponseMessage responseMessage = new ResponseMessage();

            responseMessage = _vendorRepository.UpdateVendor(vendor, id);
            return(responseMessage);
        }
Example #3
0
 public static void vendorsForAddBuyingInvoice(MSComboBox comboBox)
 {
     try {
         if (vendorDataTable == null)
         {
             vendorDataTable = new DataTable();
             vendorDataTable.Columns.Add("ID", typeof(int));
             vendorDataTable.Columns.Add("name", typeof(String));
         }
         else
         {
             vendorDataTable.Rows.Clear();
         }
         List <Vendor> list = vendorManagerImpl.getAllActivedVendors();
         foreach (Vendor vendor in list)
         {
             vendorDataTable.Rows.Add(vendor.Id, vendor.Name);
         }
         if (Session.Permission["canAddVendor"] == 1 && comboBox.AddLinkWindow == null)
         {
             if (addVendor == null)
             {
                 addVendor = new AddVendor(comboBox);
             }
             comboBox.AddLinkWindow = addVendor;
         }
         comboBox.IsPermissionDenied = Session.Permission["canAddVendor"] == 0 ? true : false;
         comboBox.OptionGroup        = vendorDataTable;
     } catch (Exception) {
     }
 }
        public ResponseMessage CreateVendor(AddVendor vendor)
        {
            try {
                if (_context.SubContractor.Where(x => x.Name == vendor.Name && x.IsDelete == false).Count() > 0)
                {
                    throw new ValueNotFoundException("Vendor  Name already exist.");
                }
                ResponseMessage responseMessage = new ResponseMessage();
                SubContractor   sc = _mapper.Map <SubContractor> (vendor);
                sc.CreatedAt = DateTime.Now;
                sc.CreatedBy = 1; //TODO
                _context.SubContractor.Add(sc);
                _context.SaveChanges();

                //Add the sub contractor service type
                if (vendor.VendorServiceTypeDetails.Any())
                {
                    foreach (var item in vendor.VendorServiceTypeDetails)
                    {
                        SubContractorServiceType subContractorServiceType = new SubContractorServiceType();
                        subContractorServiceType.SubcontId     = vendor.Id;
                        subContractorServiceType.ServicetypeId = item.ServiceTypeId;
                        _context.SubContractorServiceType.Add(subContractorServiceType);
                    }
                }

                responseMessage.Message = "Vendor created sucessfully";
                return(responseMessage);
            } catch (Exception ex) {
                throw ex;
            }
        }
Example #5
0
 public IActionResult Update(AddVendor vendor, int id)
 {
     try {
         var response = _vendorService.UpdateVendor(vendor, id);
         return(Ok(new { message = response.Message, code = 204 }));
     } catch (ValueNotFoundException e) {
         Util.LogError(e);
         return(StatusCode(StatusCodes.Status422UnprocessableEntity, new ErrorClass()
         {
             code = StatusCodes.Status422UnprocessableEntity.ToString(), message = e.Message
         }));
     } catch (Exception e) {
         Util.LogError(e);
         return(StatusCode(StatusCodes.Status500InternalServerError, new ErrorClass()
         {
             code = StatusCodes.Status500InternalServerError.ToString(), message = "Something went wrong"
         }));
     }
 }
Example #6
0
 public VendorManagerControler(AddVendor addVendor, MSComboBox mSComboBox)
 {
     this.addVendor    = addVendor;
     this.mSComboBox   = mSComboBox;
     vendorManagerImpl = new VendorManagerImpl(addVendor);
 }
Example #7
0
 public VendorManagerImpl(AddVendor addVendor)
 {
     this.addVendor = addVendor;
     dao            = VendorDao.getInstance();
 }
        public ResponseMessage UpdateVendor(AddVendor vendor, int id)
        {
            ResponseMessage responseMessage = new ResponseMessage();

            try {
                var sc = _context.SubContractor.Where(x => x.Id == id && x.IsDelete == false)
                         .Include(s => s.SubContractorServiceType).FirstOrDefault();
                if (sc != null)
                {
                    if (_context.SubContractor.Where(x => x.Name == vendor.Name && x.Id != id && x.IsDelete == false).Count() > 0)
                    {
                        throw new ValueNotFoundException("Vendor Name already exist.");
                    }
                    else
                    {
                        sc.Name       = vendor.Name;
                        sc.VendorCode = vendor.VendorCode;
                        sc.IsStatus   = vendor.IsStatus;
                        sc.UpdatedBy  = 1; //TODO
                        sc.UpdatedAt  = DateTime.Now;
                        _context.SaveChanges();

                        var subcontractorServiceType = sc.SubContractorServiceType;
                        var addedSubConService       = vendor.VendorServiceTypeDetails.Where(x => !subcontractorServiceType.Any(s => s.Id == x.Id)).ToList();
                        var deletedSubConService     = subcontractorServiceType.Where(x => !vendor.VendorServiceTypeDetails.Any(s => s.Id == x.Id)).ToList();
                        var updatedSubConService     = vendor.VendorServiceTypeDetails.Where(x => subcontractorServiceType.Any(p => p.Id == x.Id)).ToList();

                        //add Project site Location
                        if (addedSubConService.Any())
                        {
                            foreach (var item in addedSubConService)
                            {
                                SubContractorServiceType subConServiceType = new SubContractorServiceType();
                                subConServiceType.Id            = item.Id;
                                subConServiceType.SubcontId     = vendor.Id;
                                subConServiceType.ServicetypeId = item.ServiceTypeId;
                                _context.SubContractorServiceType.Add(subConServiceType);
                            }
                        }

                        //delete Project site Location
                        if (deletedSubConService.Any())
                        {
                            foreach (var item in deletedSubConService)
                            {
                                _context.SubContractorServiceType.Remove(item);
                            }
                        }

                        //update Project site Location
                        if (updatedSubConService.Any())
                        {
                            foreach (var item in updatedSubConService)
                            {
                                SubContractorServiceType subConServiceType = new SubContractorServiceType();
                                subConServiceType.SubcontId     = id;
                                subConServiceType.ServicetypeId = item.ServiceTypeId;
                            }
                        }

                        _context.SaveChanges();

                        AuditLogs audit = new AuditLogs()
                        {
                            Action    = "Vendor",
                            Message   = string.Format("Vendor Updated  Succussfully {0}", vendor.Name),
                            CreatedAt = DateTime.Now,
                            CreatedBy = 1 //TODO
                        };
                        _commonRepo.AuditLog(audit);
                        return(responseMessage = new ResponseMessage()
                        {
                            Message = "Vendor updated successfully.",
                        });
                    }
                }
                else
                {
                    throw new ValueNotFoundException("Vendor not available.");
                }
            } catch (Exception ex) {
                throw ex;
            }
        }