public void AddNewSupplier(SuppliersView model, string userId)
        {
            using (var supplier = new SuppliersRepository())
            {
                var supp = new Suppliers
                {
                    SupplierId       = model.SupplierId,
                    EmailAddress     = model.EmailAddress,
                    PhysicalAddress  = model.PhysicalAddress,
                    Status           = "Waiting For Approval",
                    SupplierCellNo   = model.SupplierCellNo,
                    SupplierLastName = model.SupplierLastName,
                    SupplierName     = model.SupplierName,
                    SupplierTelNo    = model.SupplierTelNo,
                    UserId           = userId,
                    ShortCode        = ""
                };
                supplier.Insert(supp);

                //update
                supp.ShortCode = (Guid.NewGuid().ToString().Substring(0, 4) + "-" + supp.SupplierId + "-"
                                  + model.SupplierName.Substring(0, 1) + model.SupplierLastName.Substring(0, 1)).ToUpper();
                supplier.Update(supp);
            }
        }
Exemplo n.º 2
0
        public ActionResult Edit(Supplier supplier)
        {
            if (!Authorized(RoleType.SystemManager))
            {
                return(Error(Loc.Dic.error_no_permission));
            }

            if (ModelState.IsValid)
            {
                Supplier supplierFromDB;
                bool     wasUpdated;
                using (SuppliersRepository supplierRep = new SuppliersRepository(CurrentUser.CompanyId))
                {
                    supplierFromDB = supplierRep.GetEntity(supplier.Id);

                    if (supplierFromDB == null)
                    {
                        return(Error(Loc.Dic.error_supplier_not_found));
                    }

                    if (supplierFromDB.CompanyId != CurrentUser.CompanyId)
                    {
                        return(Error(Loc.Dic.error_no_permission));
                    }

                    supplierFromDB.Name             = supplier.Name;
                    supplierFromDB.ExternalId       = supplier.ExternalId;
                    supplierFromDB.Activity_Hours   = supplier.Activity_Hours;
                    supplierFromDB.Additional_Phone = supplier.Additional_Phone;
                    supplierFromDB.Address          = supplier.Address;
                    supplierFromDB.Branch_line      = supplier.Branch_line;
                    supplierFromDB.Crew_Number      = supplier.Crew_Number;
                    supplierFromDB.Customer_Number  = supplier.Customer_Number;
                    supplierFromDB.EMail            = supplier.EMail;
                    supplierFromDB.Fax            = supplier.Fax;
                    supplierFromDB.Notes          = supplier.Notes;
                    supplierFromDB.Phone_Number   = supplier.Phone_Number;
                    supplierFromDB.Presentor_name = supplier.Presentor_name;
                    supplierFromDB.VAT_Number     = supplier.VAT_Number;

                    if (supplierRep.Update(supplierFromDB) != null)
                    {
                        return(RedirectToAction("Index"));
                    }
                    else
                    {
                        return(Error(Loc.Dic.error_database_error));
                    }
                }
            }
            else
            {
                return(Error(ModelState));
            }
        }
Exemplo n.º 3
0
 public JsonResult UpdateSupplier(Suppliers pSuppliers)
 {
     try
     {
         var result = dataSource.Update(pSuppliers);
         return(Json(new { result = result }, JsonRequestBehavior.AllowGet));
     }
     catch (Exception ex)
     {
         return(Json(new { result = false, msg = ex.Message }, JsonRequestBehavior.AllowGet));
     }
 }
Exemplo n.º 4
0
        public ActionResult Edit(SuppliersBaseViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                var supplier = viewModel.Supplier;

                _suppliersRepository.Update(supplier);

                TempData["Message"] = "Le fournisseur a été modifié correctement.";

                return(RedirectToAction("Index"));
            }

            viewModel.Init(_suppliersRepository);

            return(View(viewModel));
        }
        //owner approval
        public void Approve(SuppliersView model)
        {
            using (var supplier = new SuppliersRepository())
            {
                var supp = supplier.GetById(model.SupplierId);
                if (supp != null)
                {
                    supp.SupplierId       = model.SupplierId;
                    supp.Status           = model.Status;
                    supp.SupplierId       = supp.SupplierId;
                    supp.EmailAddress     = supp.EmailAddress;
                    supp.PhysicalAddress  = supp.PhysicalAddress;
                    supp.ShortCode        = supp.ShortCode;
                    supp.SupplierCellNo   = supp.SupplierCellNo;
                    supp.SupplierLastName = supp.SupplierLastName;
                    supp.SupplierName     = supp.SupplierName;
                    supp.UserId           = supp.UserId;
                    supp.SupplierTelNo    = model.SupplierTelNo;

                    supplier.Update(supp);
                }
            }
        }
Exemplo n.º 6
0
        public static string ImportSuppliers(Stream stream, int companyId)
        {
            const int       EXTERNALID     = 0;
            const int       NAME           = 1;
            List <Supplier> toAddSuppliers = new List <Supplier>();

            byte[] fileBytes = new byte[stream.Length];
            stream.Read(fileBytes, 0, Convert.ToInt32(stream.Length));
            string fileContent = System.Text.Encoding.Default.GetString(fileBytes);

            string[] fileLines       = fileContent.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
            int      firstValuesLine = 0;
            bool     noErros         = true;
            string   errorType       = String.Empty;

            using (SuppliersRepository suppliersRep = new SuppliersRepository(companyId))
            {
                for (int i = firstValuesLine; i < fileLines.Length; i++)
                {
                    string[] lineValues = fileLines[i].Split('\t');
                    for (int vIndex = 0; vIndex < lineValues.Length; vIndex++)
                    {
                        lineValues[vIndex] = lineValues[vIndex].Replace("\"", "");
                    }

                    Supplier newSupplier;
                    if (!(int.Parse(lineValues[EXTERNALID]) > 0))
                    {
                        errorType = Loc.Dic.error_invalid_form;
                        break;
                    }
                    if (lineValues[NAME] == null)
                    {
                        errorType = Loc.Dic.error_invalid_form;
                        break;
                    }
                    try
                    {
                        newSupplier = new Supplier()
                        {
                            CompanyId  = companyId,
                            ExternalId = lineValues[EXTERNALID],
                            Name       = lineValues[NAME],
                        };
                    }
                    catch
                    {
                        noErros   = false;
                        errorType = Loc.Dic.Error_FileParseError;
                        break;
                    }
                    List <Supplier> existingSuppliers = suppliersRep.GetList().Where(x => x.CompanyId == companyId && x.ExternalId == newSupplier.ExternalId).ToList();
                    if (existingSuppliers.Count == 0)
                    {
                        toAddSuppliers.Add(newSupplier);
                    }
                    else
                    {
                        foreach (Supplier supplier in existingSuppliers)
                        {
                            supplier.Name = lineValues[NAME];
                            suppliersRep.Update(supplier);
                        }
                    }
                }
                if (!suppliersRep.AddList(toAddSuppliers))
                {
                    noErros   = false;
                    errorType = Loc.Dic.error_database_error;
                }
            }
            if (!noErros)
            {
                return(errorType);
            }
            return("OK");
        }
Exemplo n.º 7
0
        public static string ImportSuppliers(Stream stream, int companyId)
        {
            const int EXTERNALID = 0;
            const int NAME = 1;
            List<Supplier> toAddSuppliers = new List<Supplier>();
            byte[] fileBytes = new byte[stream.Length];
            stream.Read(fileBytes, 0, Convert.ToInt32(stream.Length));
            string fileContent = System.Text.Encoding.Default.GetString(fileBytes);

            string[] fileLines = fileContent.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
            int firstValuesLine = 0;
            bool noErros = true;
            string errorType = String.Empty;
            using (SuppliersRepository suppliersRep = new SuppliersRepository(companyId))
            {
                for (int i = firstValuesLine; i < fileLines.Length; i++)
                {
                    string[] lineValues = fileLines[i].Split('\t');
                    for (int vIndex = 0; vIndex < lineValues.Length; vIndex++)
                    {
                        lineValues[vIndex] = lineValues[vIndex].Replace("\"", "");
                    }

                    Supplier newSupplier;
                    if (!(int.Parse(lineValues[EXTERNALID]) > 0))
                    {
                        errorType = Loc.Dic.error_invalid_form;
                        break;
                    }
                    if (lineValues[NAME] == null)
                    {
                        errorType = Loc.Dic.error_invalid_form;
                        break;
                    }
                    try
                    {
                        newSupplier = new Supplier()
                        {
                            CompanyId = companyId,
                            ExternalId = lineValues[EXTERNALID],
                            Name = lineValues[NAME],
                        };
                    }
                    catch
                    {
                        noErros = false;
                        errorType = Loc.Dic.Error_FileParseError;
                        break;
                    }
                    List<Supplier> existingSuppliers = suppliersRep.GetList().Where(x => x.CompanyId == companyId && x.ExternalId == newSupplier.ExternalId).ToList();
                    if (existingSuppliers.Count == 0) toAddSuppliers.Add(newSupplier);
                    else
                    {
                        foreach (Supplier supplier in existingSuppliers)
                        {
                            supplier.Name = lineValues[NAME];
                            suppliersRep.Update(supplier);
                        }
                    }
                }
                if (!suppliersRep.AddList(toAddSuppliers))
                {
                    noErros = false;
                    errorType = Loc.Dic.error_database_error;
                }
            }
            if (!noErros) return errorType;
            return "OK";
        }
Exemplo n.º 8
0
        public ActionResult Edit(Supplier supplier)
        {
            if (!Authorized(RoleType.SystemManager))
                return Error(Loc.Dic.error_no_permission);

            if (ModelState.IsValid)
            {
                Supplier supplierFromDB;
                bool wasUpdated;
                using (SuppliersRepository supplierRep = new SuppliersRepository(CurrentUser.CompanyId))
                {
                    supplierFromDB = supplierRep.GetEntity(supplier.Id);

                    if (supplierFromDB == null)
                        return Error(Loc.Dic.error_supplier_not_found);

                    if (supplierFromDB.CompanyId != CurrentUser.CompanyId)
                        return Error(Loc.Dic.error_no_permission);

                    supplierFromDB.Name = supplier.Name;
                    supplierFromDB.ExternalId = supplier.ExternalId;
                    supplierFromDB.Activity_Hours = supplier.Activity_Hours;
                    supplierFromDB.Additional_Phone = supplier.Additional_Phone;
                    supplierFromDB.Address = supplier.Address;
                    supplierFromDB.Branch_line = supplier.Branch_line;
                    supplierFromDB.Crew_Number = supplier.Crew_Number;
                    supplierFromDB.Customer_Number = supplier.Customer_Number;
                    supplierFromDB.EMail = supplier.EMail;
                    supplierFromDB.Fax = supplier.Fax;
                    supplierFromDB.Notes = supplier.Notes;
                    supplierFromDB.Phone_Number = supplier.Phone_Number;
                    supplierFromDB.Presentor_name = supplier.Presentor_name;
                    supplierFromDB.VAT_Number = supplier.VAT_Number;

                    if (supplierRep.Update(supplierFromDB) != null)
                        return RedirectToAction("Index");
                    else
                        return Error(Loc.Dic.error_database_error);
                }
            }
            else
            {
                return Error(ModelState);
            }
        }