Esempio n. 1
0
        public ActionResult Create()
        {
            using (SuppliersRepository suppliersRepository = new SuppliersRepository(CurrentUser.CompanyId))
                using (LocationsRepository locationsRepository = new LocationsRepository(CurrentUser.CompanyId))
                    using (InventoryRepository inventoryRepository = new InventoryRepository(CurrentUser.CompanyId))
                    {
                        ViewBag.RelatedInventoryItem = new SelectList(inventoryRepository.GetList("Orders_Items")
                                                                      .Select(x => new { Id = x.Id, InventarNumber = x.InventarNumber, Title = x.Orders_Items.Title, SubTitle = x.Orders_Items.SubTitle })
                                                                      .ToList()
                                                                      .Select(x => new SelectListItemDB()
                        {
                            Id = x.Id, Name = x.InventarNumber + " - " + x.Title + " " + x.SubTitle
                        })
                                                                      .OrderBy(x => x.Name)
                                                                      .ToList(), "Id", "Name");

                        if (locationsRepository.GetList().Where(x => x.CompanyId == CurrentUser.CompanyId).Count() == 0)
                        {
                            return(Error(Loc.Dic.error_no_location_exist));
                        }
                        ViewBag.LocationId = new SelectList(locationsRepository.GetList().Where(x => x.CompanyId == CurrentUser.CompanyId).OrderBy(x => x.Name).ToList(), "Id", "Name");
                        ViewBag.Suppliers  = new SelectList(suppliersRepository.GetList().Where(x => x.CompanyId == CurrentUser.CompanyId).OrderBy(x => x.Name).ToList(), "Id", "Name");
                    }

            return(View());
        }
Esempio n. 2
0
        public ActionResult Create(Supplier supplier)
        {
            //Validiation
            if (!Authorized(RoleType.OrdersWriter))
            {
                return(Error(Loc.Dic.error_no_permission));
            }
            if (!ModelState.IsValid)
            {
                return(Error(ModelState));
            }

            //Creation
            SuppliersRepository.Messeges createMessege;
            using (SuppliersRepository supplierRep = new SuppliersRepository(CurrentUser.CompanyId)) createMessege = supplierRep.Create(supplier);

            //BackToUI
            if (createMessege == SuppliersRepository.Messeges.CreatedSuccessfully)
            {
                return(RedirectToAction("Index"));
            }
            else if (createMessege == SuppliersRepository.Messeges.Error_ExternalIdExist)
            {
                return(Error(Loc.Dic.error_externalIdAlreadyExist));
            }
            return(Error(Loc.Dic.error_suppliers_create_error));
        }
        public static void MainMenuOptions(Repository repositoryOption)
        {
            switch (repositoryOption)
            {
            case Repository.GoodsRepository:
            {
                using IGoodsRepository goodsRepository = new GoodsRepository();
                var goodsRepositoryOperation = GoodsRepositoryMenu.ShowGoodsRepositoryMenu();
                GoodsRepositoryMenu.ChooseOperationForGoodsRepository(goodsRepository, goodsRepositoryOperation);
                break;
            }

            case Repository.SuppliersRepository:
            {
                using ISuppliersRepository suppliersRepository = new SuppliersRepository();
                var suppliersRepositoryOperation = SuppliersRepositoryMenu.ShowSuppliersRepositoryMenu();
                SuppliersRepositoryMenu.ChooseOperatioForSuppliersRepository(suppliersRepository, suppliersRepositoryOperation);
                break;
            }

            case Repository.TypesOfGoodsRepository:
            {
                using ITypesOfGoodsRepository typesOfGoodsRepository = new TypesOfGoodsRepository();
                var typesOgGoodsRepositoryOperation = TypesOfGoodsRepositoryMenu.ShowTypesOfGoodsRepositoryMenu();
                TypesOfGoodsRepositoryMenu.ChooseOperationForTypesOfGoodsRepository(typesOfGoodsRepository, typesOgGoodsRepositoryOperation);
                break;
            }

            default:
                Environment.Exit(0);
                break;
            }
        }
        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);
            }
        }
Esempio n. 5
0
        public ActionResult Create()
        {
            if (Authorized(RoleType.OrdersWriter))
            {
                List<Supplier> allSuppliers;
                using (SuppliersRepository suppliersRep = new SuppliersRepository(CurrentUser.CompanyId))
                {
                    allSuppliers = suppliersRep.GetList().ToList();
                }

                if (allSuppliers != null)
                {
                    ViewBag.SupplierId = new SelectList(allSuppliers, "Id", "Name");
                    return View();
                }
                else
                {
                    return Error(Loc.Dic.error_suppliers_get_error);
                }
            }
            else
            {
                return Error(Loc.Dic.error_no_permission);
            }
        }
Esempio n. 6
0
        public ActionResult Create()
        {
            if (Authorized(RoleType.OrdersWriter))
            {
                List <Supplier> allSuppliers;
                using (SuppliersRepository suppliersRep = new SuppliersRepository(CurrentUser.CompanyId))
                {
                    allSuppliers = suppliersRep.GetList().ToList();
                }

                if (allSuppliers != null)
                {
                    ViewBag.SupplierId = new SelectList(allSuppliers, "Id", "Name");
                    return(View());
                }
                else
                {
                    return(Error(Loc.Dic.error_suppliers_get_error));
                }
            }
            else
            {
                return(Error(Loc.Dic.error_no_permission));
            }
        }
Esempio n. 7
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));
            }
        }
Esempio n. 8
0
        public JsonResult GetAll(bool firstNull = false)
        {
            if (Authorized(RoleType.OrdersWriter))
            {
                List <AjaxSupplier> allSuppliers;
                using (SuppliersRepository suppRep = new SuppliersRepository(CurrentUser.CompanyId))
                {
                    allSuppliers = suppRep.GetList()
                                   .Where(x => x.CompanyId == CurrentUser.CompanyId)
                                   .Select(
                        supp => new AjaxSupplier()
                    {
                        Id               = supp.Id,
                        Name             = supp.Name,
                        VAT_Number       = supp.VAT_Number.HasValue ? supp.VAT_Number.Value : 0,
                        Phone_Number     = supp.Phone_Number,
                        Activity_Hours   = supp.Activity_Hours,
                        Additional_Phone = supp.Additional_Phone,
                        Address          = supp.Address,
                        Branch_Line      = supp.Branch_line,
                        City             = supp.City,
                        Crew_Number      = supp.Crew_Number,
                        Customer_Number  = supp.Customer_Number,
                        EMail            = supp.EMail,
                        Fax              = supp.Fax,
                        Presentor_name   = supp.Presentor_name,
                        Notes            = supp.Notes,
                        CreationDate     = supp.CreationDate
                    })
                                   .ToList();
                }

                if (firstNull)
                {
                    allSuppliers.Insert(0, new AjaxSupplier()
                    {
                        Id = null, Name = Loc.Dic.SelectNone
                    });
                }

                if (allSuppliers != null)
                {
                    return(Json(new { gotData = true, data = allSuppliers, message = String.Empty }, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    return(Json(new { gotData = false, message = Loc.Dic.error_suppliers_get_error }, JsonRequestBehavior.AllowGet));
                }
            }
            else
            {
                return(Json(new { gotData = false, message = Loc.Dic.error_no_permission }, JsonRequestBehavior.AllowGet));
            }
        }
Esempio n. 9
0
        public ActionResult Create(Supplier supplier)
        {
            //Validiation
            if (!Authorized(RoleType.OrdersWriter)) return Error(Loc.Dic.error_no_permission);
            if (!ModelState.IsValid) return Error(ModelState);

            //Creation
            SuppliersRepository.Messeges createMessege;
            using (SuppliersRepository supplierRep = new SuppliersRepository(CurrentUser.CompanyId)) createMessege = supplierRep.Create(supplier);

            //BackToUI
            if (createMessege == SuppliersRepository.Messeges.CreatedSuccessfully) return RedirectToAction("Index");
            else if (createMessege == SuppliersRepository.Messeges.Error_ExternalIdExist) return Error(Loc.Dic.error_externalIdAlreadyExist);
            return Error(Loc.Dic.error_suppliers_create_error);
        }
 /// <summary>
 /// Initializes the view model.
 /// </summary>
 public void Init(ProductTypesRepository productTypesRepository,
                  SuppliersRepository suppliersRepository,
                  UnitsRepository unitsRepository,
                  string userId)
 {
     ProductTypesSelectListItems = new SelectList(
         productTypesRepository.GetList(),
         "Id", "Name");
     SuppliersSelectListItems = new SelectList(
         suppliersRepository.GetList(),
         "Id", "Name");
     UnitsSelectListItems = new SelectList(
         unitsRepository.GetList(),
         "Id", "Name", "Quantity");
 }
Esempio n. 11
0
        public ActionResult Details(int id = 0)
        {
            Supplier supplier;

            using (SuppliersRepository supplierssRep = new SuppliersRepository(CurrentUser.CompanyId))
            {
                supplier = supplierssRep.GetEntity(id);
            }

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

            return(View(supplier));
        }
 public ProductsController(ProductsRepository productsRepository,
                           InventoriesRepository inventoriesRepository,
                           SuppliersRepository suppliersRepository,
                           ProductTypesRepository productTypesRepository,
                           UnitsRepository unitsRepository,
                           InventoryInputsRepository inventoryInputsRepository,
                           ProductModificationsRepository productModificationsRepository)
 {
     _productsRepository             = productsRepository;
     _inventoriesRepository          = inventoriesRepository;
     _productTypesRepository         = productTypesRepository;
     _suppliersRepository            = suppliersRepository;
     _unitsRepository                = unitsRepository;
     _inventoryInputsRepository      = inventoryInputsRepository;
     _productModificationsRepository = productModificationsRepository;
 }
Esempio n. 13
0
        public ActionResult Index(int page = FIRST_PAGE, string sortby = DEFAULT_SORT, string order = DEFAULT_DESC_ORDER)
        {
            if (!Authorized(RoleType.SystemManager))
            {
                return(Error(Loc.Dic.error_no_permission));
            }

            IEnumerable <Supplier> suppliers;

            using (SuppliersRepository suppliersRep = new SuppliersRepository(CurrentUser.CompanyId))
            {
                suppliers = suppliersRep.GetList().Where(x => x.CompanyId == CurrentUser.CompanyId);

                suppliers = Pagination(suppliers, page, sortby, order);

                return(View(suppliers.ToList()));
            }
        }
Esempio n. 14
0
        public JsonResult AjaxCreate(Supplier supplier)
        {
            if (Authorized(RoleType.OrdersWriter))
            {
                supplier.CompanyId = CurrentUser.CompanyId;

                SuppliersRepository.Messeges messege;
                using (SuppliersRepository supplierRep = new SuppliersRepository(CurrentUser.CompanyId)) messege = supplierRep.Create(supplier);

                if (messege == SuppliersRepository.Messeges.CreatedSuccessfully)
                    return Json(new { success = true, message = String.Empty, newSupplierId = supplier.Id.ToString() }, JsonRequestBehavior.AllowGet);
                else
                    return Json(new { success = false, message = Loc.Dic.error_suppliers_create_error }, JsonRequestBehavior.AllowGet);
            }
            else
            {
                return Json(new { success = false, message = Loc.Dic.error_no_permission }, JsonRequestBehavior.AllowGet);
            }
        }
 public List <SuppliersView> GetAllSuppliers()
 {
     using (var supplier = new SuppliersRepository())
     {
         return(supplier.GetAll().Select(x => new SuppliersView
         {
             SupplierId = x.SupplierId,
             EmailAddress = x.EmailAddress,
             PhysicalAddress = x.PhysicalAddress,
             ShortCode = x.ShortCode,
             Status = x.Status,
             SupplierCellNo = x.SupplierCellNo,
             SupplierLastName = x.SupplierLastName,
             SupplierName = x.SupplierName,
             SupplierTelNo = x.SupplierCellNo,
             UserId = x.UserId
         }).ToList());
     }
 }
 public List <SuppliersView> GetAllSuppliersApproved()
 {
     using (var supplier = new SuppliersRepository())
     {
         List <Suppliers> returnList = supplier.GetAll().Where(x => x.Status == "Approved").ToList();
         return(returnList.Select(x => new SuppliersView
         {
             SupplierId = x.SupplierId,
             EmailAddress = x.EmailAddress,
             PhysicalAddress = x.PhysicalAddress,
             ShortCode = x.ShortCode,
             Status = x.Status,
             SupplierCellNo = x.SupplierCellNo,
             SupplierLastName = x.SupplierLastName,
             SupplierName = x.SupplierName,
             SupplierTelNo = x.SupplierCellNo,
             UserId = x.UserId
         }).ToList());
     }
 }
Esempio n. 17
0
        public ActionResult Index()
        {
            StaffRepository     staff    = new StaffRepository();
            SuppliersRepository Supplier = new SuppliersRepository();

            staff.CreateStaff();
            staff.InsertStaff_StoredProcedure();
            staff.UpdateStaff();
            staff.GetStaff();
            //staff.DeleteWardStaffAllocation();
            //staff.DeleteStaff();
            staff.GetStaffView();

            Supplier.CreateSupplier();
            Supplier.UpdateSupplier();
            Supplier.GetSupplier();
            //Supplier.DeleteSupplier();

            return(View());
        }
Esempio n. 18
0
        public ActionResult Create()
        {
            using (SuppliersRepository suppliersRepository = new SuppliersRepository(CurrentUser.CompanyId))
            using (LocationsRepository locationsRepository = new LocationsRepository(CurrentUser.CompanyId))
            using (InventoryRepository inventoryRepository = new InventoryRepository(CurrentUser.CompanyId))
            {
                ViewBag.RelatedInventoryItem = new SelectList(inventoryRepository.GetList("Orders_Items")
                                  .Select( x => new { Id = x.Id, InventarNumber = x.InventarNumber, Title = x.Orders_Items.Title, SubTitle = x.Orders_Items.SubTitle })
                                  .ToList()
                  .Select(x => new SelectListItemDB() { Id = x.Id, Name = x.InventarNumber + " - " + x.Title + " " + x.SubTitle })
                  .OrderBy(x => x.Name)
                  .ToList(), "Id", "Name");

                if (locationsRepository.GetList().Where(x => x.CompanyId == CurrentUser.CompanyId).Count() == 0)
                    return Error(Loc.Dic.error_no_location_exist);
                ViewBag.LocationId = new SelectList(locationsRepository.GetList().Where(x => x.CompanyId == CurrentUser.CompanyId).OrderBy(x => x.Name).ToList(), "Id", "Name");
                ViewBag.Suppliers = new SelectList(suppliersRepository.GetList().Where(x => x.CompanyId == CurrentUser.CompanyId).OrderBy(x=>x.Name).ToList(), "Id", "Name");
            }

            return View();
        }
        /// <summary>
        /// Deletes a Supplier
        /// Level: Logic
        /// </summary>
        /// <param name="ID">The Supplier ID</param>
        /// <returns>True if Successful, False if Not</returns>
        public bool DeleteSupplier(int ID)
        {
            try
            {
                SuppliersRepository myRepository = new SuppliersRepository();

                if ((!myRepository.SupplierHasOrders(ID)) & (!myRepository.SupplierHasProducts(ID)))
                {
                    myRepository.DeleteSupplier(ID);
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception Exception)
            {
                throw Exception;
            }
        }
        /// <summary>
        /// Adds a Supplier
        /// Level: Logic
        /// </summary>
        /// <param name="Supplier">The Supplier Name</param>
        /// <param name="Email">The Supplier Email</param>
        /// <param name="Postcode">The Postcode</param>
        /// <param name="StreetAddress">The Street Address</param>
        /// <param name="Town">The Town</param>
        /// <param name="Country">The Country</param>
        public void AddSupplier(string Supplier, string Email, string Postcode, string StreetAddress,
                                string Town, string Country)
        {
            try
            {
                SuppliersRepository myRepository = new SuppliersRepository();

                Supplier mySupplier = new Supplier();

                mySupplier.Supplier1     = Supplier;
                mySupplier.Email         = Email;
                mySupplier.Postcode      = Postcode;
                mySupplier.StreetAddress = StreetAddress;

                Town myTown = myRepository.RetrieveTown(Town, Country);

                //If Town Exists
                if (myTown != null)
                {
                    //Assigning Existent Town to Supplier
                    mySupplier.Town = myTown;
                }
                else
                {
                    //Instanciating New Town
                    myTown         = new Town();
                    myTown.Town1   = Town;
                    myTown.Country = myRepository.RetrieveCountry(Country);

                    //Assigning New Town to Supplier
                    mySupplier.Town = myTown;
                }

                myRepository.AddSupplier(mySupplier);
            }
            catch (Exception Exception)
            {
                throw Exception;
            }
        }
 public SuppliersView GetSupplierById(int id)
 {
     using (var supplier = new SuppliersRepository())
     {
         Suppliers supp     = supplier.GetById(id);
         var       suppView = new SuppliersView();
         if (supp != null)
         {
             suppView.SupplierId       = supp.SupplierId;
             suppView.EmailAddress     = supp.EmailAddress;
             suppView.Status           = supp.Status;
             suppView.PhysicalAddress  = supp.PhysicalAddress;
             suppView.ShortCode        = supp.ShortCode;
             suppView.SupplierCellNo   = supp.SupplierCellNo;
             suppView.SupplierLastName = supp.SupplierLastName;
             suppView.SupplierName     = supp.SupplierName;
             suppView.UserId           = supp.UserId;
             suppView.SupplierTelNo    = supp.SupplierTelNo;
         }
         return(suppView);
     }
 }
        //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);
                }
            }
        }
Esempio n. 23
0
        public JsonResult AjaxCreate(Supplier supplier)
        {
            if (Authorized(RoleType.OrdersWriter))
            {
                supplier.CompanyId = CurrentUser.CompanyId;

                SuppliersRepository.Messeges messege;
                using (SuppliersRepository supplierRep = new SuppliersRepository(CurrentUser.CompanyId)) messege = supplierRep.Create(supplier);

                if (messege == SuppliersRepository.Messeges.CreatedSuccessfully)
                {
                    return(Json(new { success = true, message = String.Empty, newSupplierId = supplier.Id.ToString() }, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    return(Json(new { success = false, message = Loc.Dic.error_suppliers_create_error }, JsonRequestBehavior.AllowGet));
                }
            }
            else
            {
                return(Json(new { success = false, message = Loc.Dic.error_no_permission }, JsonRequestBehavior.AllowGet));
            }
        }
        /// <summary>
        /// Updates a Supplier
        /// Level: Logic
        /// </summary>
        /// <param name="ID">The Supplier ID</param>
        /// <param name="Supplier">The Supplier Name</param>
        /// <param name="Email">The Email</param>
        /// <param name="Postcode">The Postcode</param>
        /// <param name="StreetAddress">The Street Address</param>
        /// <param name="Town">The Town</param>
        /// <param name="Country">The Country</param>
        public void UpdateSupplier(int ID, string Supplier, string Email, string Postcode, string StreetAddress,
                                   string Town, string Country)
        {
            try
            {
                SuppliersRepository myRepository = new SuppliersRepository();

                SuppliersView mySupplier = new SuppliersView();

                mySupplier.Id            = ID;
                mySupplier.Supplier      = Supplier;
                mySupplier.Email         = Email;
                mySupplier.Postcode      = Postcode;
                mySupplier.StreetAddress = StreetAddress;
                mySupplier.Town          = Town;
                mySupplier.Country       = Country;

                myRepository.UpdateSupplier(mySupplier);
            }
            catch (Exception Exception)
            {
                throw Exception;
            }
        }
Esempio n. 25
0
        public ActionResult Index(int page = FIRST_PAGE, string sortby = DEFAULT_SORT, string order = DEFAULT_DESC_ORDER)
        {
            if (!Authorized(RoleType.SystemManager))
                return Error(Loc.Dic.error_no_permission);

            IEnumerable<Supplier> suppliers;
            using (SuppliersRepository suppliersRep = new SuppliersRepository(CurrentUser.CompanyId))
            {
                suppliers = suppliersRep.GetList().Where(x => x.CompanyId == CurrentUser.CompanyId);

                suppliers = Pagination(suppliers, page, sortby, order);

                return View(suppliers.ToList());
            }
        }
Esempio n. 26
0
 public SuppliersController()
 {
     this.dataSource = new SuppliersRepository();
 }
Esempio n. 27
0
        public ActionResult Create()
        {
            if (!Authorized(RoleType.OrdersWriter)) return Error(Loc.Dic.error_no_permission);

            using (SuppliersRepository suppliersRep = new SuppliersRepository(CurrentUser.CompanyId))
            using (BudgetsRepository budgetsRep = new BudgetsRepository(CurrentUser.CompanyId))
            using (AllocationRepository allocationsRep = new AllocationRepository(CurrentUser.CompanyId))
            {
                List<Supplier> allSuppliers = suppliersRep.GetList().Where(x => x.ExternalId != null).OrderBy(s => s.Name).ToList();
                if (!allSuppliers.Any()) return Error(Loc.Dic.error_no_suppliers_for_order);

                ViewBag.SupplierId = new SelectList(allSuppliers, "Id", "Name");

                Budget activeBudget = budgetsRep.GetList().SingleOrDefault(x => x.IsActive);
                if (activeBudget == null) return Error(Loc.Dic.error_no_active_budget);

                ViewBag.Allocations = allocationsRep.GetUserAllocations(CurrentUser.UserId, activeBudget.Id);
                if (!((List<Budgets_Allocations>)ViewBag.Allocations).Any()) return Error(Loc.Dic.error_user_have_no_allocations);
                ViewBag.BudgetYear = activeBudget.Year;
                return View();
            }
        }
Esempio n. 28
0
        public ActionResult SearchForm(OrdersSearchValuesModel model, bool isExpanding, bool isCollapsed, int? userId = null, int? statusId = null, int? supplierId = null, bool hideUserField = false, bool hideStatusField = false, bool hideSupplierField = false)
        {
            if (model == null) model = new OrdersSearchValuesModel();

            using (UsersRepository usersRep = new UsersRepository(CurrentUser.CompanyId))
            using (BudgetsRepository budgetsRep = new BudgetsRepository(CurrentUser.CompanyId))
            using (SuppliersRepository suppliersRep = new SuppliersRepository(CurrentUser.CompanyId))
            using (OrderStatusesRepository statusesRep = new OrderStatusesRepository())
            using (AllocationRepository allocationsRep = new AllocationRepository(CurrentUser.CompanyId))
            {
                List<SelectListItemDB> usersAsSelectItems = new List<SelectListItemDB>() { new SelectListItemDB() { Id = -1, Name = Loc.Dic.AllUsersOption } };
                usersAsSelectItems.AddRange(usersRep.GetList().Select(x => new SelectListItemDB() { Id = x.Id, Name = x.FirstName + " " + x.LastName }));
                model.UsersList = new SelectList(usersAsSelectItems, "Id", "Name");

                List<SelectListItemDB> budgetsAsSelectItems = new List<SelectListItemDB>() { new SelectListItemDB() { Id = -1, Name = Loc.Dic.AllBudgetsOption } };
                budgetsAsSelectItems.AddRange(budgetsRep.GetList().AsEnumerable().Select(x => new SelectListItemDB() { Id = x.Id, Name = "(" + x.Year + ") " + x.Name }));
                model.BudgetsList = new SelectList(budgetsAsSelectItems, "Id", "Name");

                List<Supplier> suppliersSelectList = new List<Supplier>() { new Supplier() { Id = -1, Name = Loc.Dic.AllSuppliersOption } };
                suppliersSelectList.AddRange(suppliersRep.GetList().OrderByDescending(x => x.Name).ToList());
                model.SuppliersList = new SelectList(suppliersSelectList, "Id", "Name");

                List<Orders_Statuses> statusesSelectList = new List<Orders_Statuses>() { new Orders_Statuses() { Id = -1, Name = Loc.Dic.AllStatusesOption } };
                statusesSelectList.AddRange(statusesRep.GetList().ToList());
                model.StatusesList = new SelectList(statusesSelectList, "Id", "Name");

                List<SelectListStringItem> allocationsSelectList = new List<SelectListStringItem>() { new SelectListStringItem() { Id = "-1", Name = Loc.Dic.AllAllocationsOption } };
                allocationsSelectList.AddRange(allocationsRep.GetList().GroupBy(x => x.ExternalId).AsEnumerable().Select(x => new SelectListStringItem() { Id = x.First().ExternalId, Name = x.First().DisplayName }).ToList());
                model.AllocationsList = new SelectList(allocationsSelectList, "Id", "Name");
            }

            ViewBag.IsExpanding = isExpanding;
            ViewBag.IsCollapsed = isCollapsed;
            ViewBag.UserId = userId;
            ViewBag.StatusId = statusId;
            ViewBag.SupplierId = supplierId;
            ViewBag.HideUserField = hideUserField;
            ViewBag.HideStatusField = hideStatusField;
            ViewBag.HideSupplierField = hideSupplierField;
            return PartialView(model);
        }
Esempio n. 29
0
        public ActionResult Search(OrdersSearchValuesModel model)
        {
            if (!Authorized(RoleType.OrdersWriter) && !Authorized(RoleType.OrdersViewer)) return Error(Loc.Dic.error_no_permission);

            List<Order> matchingOrders;
            List<Order> TextMatchOrders = new List<Order>();

            ViewBag.UserId = model.UserId;
            ViewBag.StatusId = model.StatusId;
            ViewBag.SupplierId = model.SupplierId;
            ViewBag.HideUserField = model.HideUserField;
            ViewBag.HideStatusField = model.HideStatusField;
            ViewBag.HideSupplierField = model.HideSupplierField;

            using (OrdersRepository ordersRep = new OrdersRepository(CurrentUser.CompanyId))
            using (UsersRepository usersRep = new UsersRepository(CurrentUser.CompanyId))
            using (SuppliersRepository suppliersRep = new SuppliersRepository(CurrentUser.CompanyId))
            {
                IQueryable<Order> ordersQuery;

                ordersQuery = ordersRep.GetList("Company", "Orders_Statuses", "Supplier", "User").Where(x => x.CompanyId == CurrentUser.CompanyId);

                if (Authorized(RoleType.OrdersViewer))
                {
                    if (model.UserId.HasValue && model.UserId.Value != -1)
                        ordersQuery = ordersQuery.Where(x => x.UserId == model.UserId.Value);
                }
                else
                {
                    ordersQuery = ordersQuery.Where(x => x.UserId == CurrentUser.UserId);
                    ViewBag.UserId = CurrentUser.UserId;
                }

                if (model.BudgetId.HasValue && model.BudgetId.Value != -1)
                    ordersQuery = ordersQuery.Where(x => x.BudgetId == model.BudgetId.Value);

                if (model.OrderNumber.HasValue && model.OrderNumber.Value != -1)
                    ordersQuery = ordersQuery.Where(x => x.OrderNumber == model.OrderNumber.Value);

                if (model.SupplierId.HasValue && model.SupplierId.Value != -1)
                    ordersQuery = ordersQuery.Where(x => x.SupplierId == model.SupplierId.Value);

                if (model.StatusId.HasValue && model.StatusId.Value != -1)
                    ordersQuery = ordersQuery.Where(x => x.StatusId == model.StatusId.Value);

                if (model.AllocationId != null && model.AllocationId != "-1")
                    ordersQuery = ordersQuery.Where(x => x.Orders_OrderToAllocation.Any(oa => oa.Budgets_Allocations.ExternalId == model.AllocationId));

                if (model.PriceMin.HasValue && model.PriceMax.HasValue && model.PriceMax.Value < model.PriceMin.Value)
                    model.PriceMax = null;

                if (model.PriceMin.HasValue)
                    ordersQuery = ordersQuery.Where(x => x.Price >= model.PriceMin.Value);

                if (model.PriceMax.HasValue)
                    ordersQuery = ordersQuery.Where(x => x.Price <= model.PriceMax.Value);

                if (model.CreationMin.HasValue && model.CreationMax.HasValue && model.CreationMax.Value < model.CreationMin.Value)
                    model.CreationMax = null;

                if (model.CreationMin.HasValue)
                    ordersQuery = ordersQuery.Where(x => x.CreationDate >= model.CreationMin.Value);

                if (model.CreationMax.HasValue)
                    ordersQuery = ordersQuery.Where(x => x.CreationDate <= model.CreationMax.Value);

                matchingOrders = ordersQuery.ToList();
            }

            if (!String.IsNullOrEmpty(model.NoteText))
            {
                List<string> searchWords = model.NoteText.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(str => str.Trim()).ToList();
                foreach (var order in matchingOrders)
                {
                    foreach (var word in searchWords)
                    {
                        if (!String.IsNullOrEmpty(order.NotesForSupplier) && order.NotesForSupplier.Contains(word))
                        {
                            TextMatchOrders.Add(order);
                            break;
                        }
                    }
                }

                model.Matches = TextMatchOrders;
            }
            else
            {
                model.Matches = matchingOrders;
            }

            return View(model);
        }
Esempio n. 30
0
        public ActionResult Details(int id = 0)
        {
            Supplier supplier;
            using (SuppliersRepository supplierssRep = new SuppliersRepository(CurrentUser.CompanyId))
            {
                supplier = supplierssRep.GetEntity(id);
            }

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

            return View(supplier);
        }
Esempio n. 31
0
 public SuppliersService(SuppliersRepository suppliersRepository)
 {
     _suppliersRepository = suppliersRepository;
 }
Esempio n. 32
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);
            }
        }
Esempio n. 33
0
 public SuppliersController(SuppliersRepository suppliersRepository)
 {
     _suppliersRepository = suppliersRepository;
 }
Esempio n. 34
0
 public static SuppliersRepository GetSuppliersRepository(IUnitOfWork unitOfWork)
 {
     var repository = new SuppliersRepository();
     repository.UnitOfWork = unitOfWork;
     return repository;
 }
Esempio n. 35
0
        public ActionResult SuppliersEntrence(int page = FIRST_PAGE, string sortby = NO_SORT_BY, string order = DEFAULT_DESC_ORDER, int VAT_Number = 0)
        {
            CultureInfo ci = new CultureInfo("He");
            System.Threading.Thread.CurrentThread.CurrentUICulture = ci;
            System.Threading.Thread.CurrentThread.CurrentCulture =
            CultureInfo.CreateSpecificCulture(ci.Name);

            using (SuppliersRepository supRep = new SuppliersRepository(CurrentUser.CompanyId))
            using (OrdersRepository orderRep = new OrdersRepository(CurrentUser.CompanyId))
            {
                Supplier supplier = supRep.GetList().SingleOrDefault(x => x.VAT_Number == VAT_Number);

                IEnumerable<Order> orders;

                orders = orderRep.GetList("Orders_Statuses", "Supplier", "User").Where(x => x.SupplierId == supplier.Id);

                if (orders != null)
                {
                    int numberOfItems = orders.Count();
                    int numberOfPages = numberOfItems / ITEMS_PER_PAGE;
                    if (numberOfItems % ITEMS_PER_PAGE != 0)
                        numberOfPages++;

                    if (page <= 0)
                        page = FIRST_PAGE;
                    if (page > numberOfPages)
                        page = numberOfPages;

                    if (sortby != NO_SORT_BY)
                    {
                        Func<Func<Order, dynamic>, IEnumerable<Order>> orderFunction;

                        if (order == DEFAULT_DESC_ORDER)
                            orderFunction = x => orders.OrderByDescending(x);
                        else
                            orderFunction = x => orders.OrderBy(x);

                        switch (sortby)
                        {
                            case "username":
                            default:
                                orders = orderFunction(x => x.User.FirstName + " " + x.User.LastName);
                                break;
                            case "number":
                                orders = orderFunction(x => x.OrderNumber);
                                break;
                            case "creation":
                                orders = orderFunction(x => x.CreationDate);
                                break;
                            case "supplier":
                                orders = orderFunction(x => x.Supplier.Name);
                                break;
                            case "status":
                                orders = orderFunction(x => x.StatusId);
                                break;
                            case "price":
                                orders = orderFunction(x => x.Price);
                                break;
                        }
                    }

                    orders = orders
                        .Skip((page - 1) * ITEMS_PER_PAGE)
                        .Take(ITEMS_PER_PAGE)
                        .ToList();

                    ViewBag.Sortby = sortby;
                    ViewBag.Order = order;
                    ViewBag.CurrPage = page;
                    ViewBag.NumberOfPages = numberOfPages;

                    return View(orders.ToList());
                }
                else
                {
                    return Error(Loc.Dic.error_order_get_error);
                }
            }
        }
Esempio n. 36
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";
        }
Esempio n. 37
0
 public static SuppliersRepository GetSuppliersRepository()
 {
     var repository = new SuppliersRepository();
     repository.UnitOfWork = GetUnitOfWork();
     return repository;
 }
 public void Init(SuppliersRepository suppliersRepository)
 {
     SuppliersSelectListItems = new SelectList(
         suppliersRepository.GetList(), "Name", "WebSite");
 }
Esempio n. 39
0
        public ActionResult SuppliersEntrence(int page = FIRST_PAGE, string sortby = NO_SORT_BY, string order = DEFAULT_DESC_ORDER, int VAT_Number = 0)
        {
            CultureInfo ci = new CultureInfo("He");

            System.Threading.Thread.CurrentThread.CurrentUICulture = ci;
            System.Threading.Thread.CurrentThread.CurrentCulture   =
                CultureInfo.CreateSpecificCulture(ci.Name);

            using (SuppliersRepository supRep = new SuppliersRepository(CurrentUser.CompanyId))
                using (OrdersRepository orderRep = new OrdersRepository(CurrentUser.CompanyId))
                {
                    Supplier supplier = supRep.GetList().SingleOrDefault(x => x.VAT_Number == VAT_Number);

                    IEnumerable <Order> orders;

                    orders = orderRep.GetList("Orders_Statuses", "Supplier", "User").Where(x => x.SupplierId == supplier.Id);

                    if (orders != null)
                    {
                        int numberOfItems = orders.Count();
                        int numberOfPages = numberOfItems / ITEMS_PER_PAGE;
                        if (numberOfItems % ITEMS_PER_PAGE != 0)
                        {
                            numberOfPages++;
                        }

                        if (page <= 0)
                        {
                            page = FIRST_PAGE;
                        }
                        if (page > numberOfPages)
                        {
                            page = numberOfPages;
                        }

                        if (sortby != NO_SORT_BY)
                        {
                            Func <Func <Order, dynamic>, IEnumerable <Order> > orderFunction;

                            if (order == DEFAULT_DESC_ORDER)
                            {
                                orderFunction = x => orders.OrderByDescending(x);
                            }
                            else
                            {
                                orderFunction = x => orders.OrderBy(x);
                            }

                            switch (sortby)
                            {
                            case "username":
                            default:
                                orders = orderFunction(x => x.User.FirstName + " " + x.User.LastName);
                                break;

                            case "number":
                                orders = orderFunction(x => x.OrderNumber);
                                break;

                            case "creation":
                                orders = orderFunction(x => x.CreationDate);
                                break;

                            case "supplier":
                                orders = orderFunction(x => x.Supplier.Name);
                                break;

                            case "status":
                                orders = orderFunction(x => x.StatusId);
                                break;

                            case "price":
                                orders = orderFunction(x => x.Price);
                                break;
                            }
                        }

                        orders = orders
                                 .Skip((page - 1) * ITEMS_PER_PAGE)
                                 .Take(ITEMS_PER_PAGE)
                                 .ToList();

                        ViewBag.Sortby        = sortby;
                        ViewBag.Order         = order;
                        ViewBag.CurrPage      = page;
                        ViewBag.NumberOfPages = numberOfPages;

                        return(View(orders.ToList()));
                    }
                    else
                    {
                        return(Error(Loc.Dic.error_order_get_error));
                    }
                }
        }
Esempio n. 40
0
        public JsonResult GetAll(bool firstNull = false)
        {
            if (Authorized(RoleType.OrdersWriter))
            {
                List<AjaxSupplier> allSuppliers;
                using (SuppliersRepository suppRep = new SuppliersRepository(CurrentUser.CompanyId))
                {
                    allSuppliers = suppRep.GetList()
                        .Where(x => x.CompanyId == CurrentUser.CompanyId)
                        .Select(
                            supp => new AjaxSupplier()
                            {
                                Id = supp.Id,
                                Name = supp.Name,
                                VAT_Number = supp.VAT_Number.HasValue ? supp.VAT_Number.Value : 0,
                                Phone_Number = supp.Phone_Number,
                                Activity_Hours = supp.Activity_Hours,
                                Additional_Phone = supp.Additional_Phone,
                                Address = supp.Address,
                                Branch_Line = supp.Branch_line,
                                City = supp.City,
                                Crew_Number = supp.Crew_Number,
                                Customer_Number = supp.Customer_Number,
                                EMail = supp.EMail,
                                Fax = supp.Fax,
                                Presentor_name = supp.Presentor_name,
                                Notes = supp.Notes,
                                CreationDate = supp.CreationDate
                            })
                        .ToList();
                }

                if (firstNull)
                    allSuppliers.Insert(0, new AjaxSupplier() { Id = null, Name = Loc.Dic.SelectNone });

                if (allSuppliers != null)
                {
                    return Json(new { gotData = true, data = allSuppliers, message = String.Empty }, JsonRequestBehavior.AllowGet);
                }
                else
                {
                    return Json(new { gotData = false, message = Loc.Dic.error_suppliers_get_error }, JsonRequestBehavior.AllowGet);
                }
            }
            else
            {
                return Json(new { gotData = false, message = Loc.Dic.error_no_permission }, JsonRequestBehavior.AllowGet);
            }
        }
Esempio n. 41
0
 public UserService(UserRepository userRepository, SuppliersRepository suppliersRepository, StationsRepository stationsRepository)
 {
     _userRepository      = userRepository;
     _suppliersRepository = suppliersRepository;
     _stationsRepository  = stationsRepository;
 }
Esempio n. 42
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");
        }