public ActionResult Edit([Bind(Include = "ID,Name,Address,Email,Phone")] Producer producer)
        {
            if (db.GetUNProducer().ID == producer.ID)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var action = new CheckController().CheckStatus("Producers");

            if (action != null)
            {
                return(action);
            }
            try
            {
                if (ModelState.IsValid)
                {
                    if (String.IsNullOrEmpty(producer.Name) ||
                        String.IsNullOrWhiteSpace(producer.Name))
                    {
                        throw new Exception($"Cannot Update Producer To Empty Name");
                    }
                    db.Update(producer);
                    return(RedirectToAction("Index"));
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);
            }

            return(View(producer));
        }
Beispiel #2
0
 public ActionResult Create(Pharmacy pharmacy)
 {
     try
     {
         if (String.IsNullOrEmpty(pharmacy.Name) ||
             String.IsNullOrWhiteSpace(pharmacy.Name))
         {
             throw new Exception($"Cannot Create Pharmacy By Empty Name");
         }
         if (_Info.Get() == null)
         {
             _Info.Add(pharmacy);
             return(RedirectToAction("Edit"));
         }
         var action = new CheckController().CheckStatus("Pharmacy_Info");
         if (action != null)
         {
             return(action);
         }
         throw new Exception();
     }
     catch (Exception ex)
     {
         ModelState.AddModelError("", ex.Message);
         return(View(pharmacy));
     }
 }
        // GET: Producers/Delete/5
        public ActionResult Delete(int id)
        {
            var action = new CheckController().CheckStatus("Producers");

            if (action != null)
            {
                return(action);
            }
            if (id == db.GetUNProducer().ID)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Producer producer = db.Get(id);

            if (producer == null)
            {
                return(HttpNotFound());
            }
            var products = new MProducts().Get_All().Where(item =>
                                                           item.Producer_ID == id).ToList();

            foreach (var item in products)
            {
                item.Category = new MCategories().Get(item.Category_ID);
            }

            ViewBag.Products = products;
            return(View(producer));
        }
        public ActionResult Create([Bind(Include = "ID,Name,Address,Email,Phone")] Producer producer)
        {
            var action = new CheckController().CheckStatus("Producers");

            if (action != null)
            {
                return(action);
            }
            try
            {
                if (ModelState.IsValid)
                {
                    if (String.IsNullOrEmpty(producer.Name) ||
                        String.IsNullOrWhiteSpace(producer.Name))
                    {
                        throw new Exception($"Cannot Create Producer By Empty Name");
                    }
                    db.Add(producer);
                    return(RedirectToAction("Index"));
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);
            }
            return(View(producer));
        }
Beispiel #5
0
        // GET: Categories/Delete/5
        public ActionResult Delete(int id)
        {
            var action = new CheckController().CheckStatus("Categories");

            if (action != null)
            {
                return(action);
            }
            //if (id == null)
            //{
            //    return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            //}
            Category categorie = db.Get(id);

            if (categorie == null)
            {
                return(HttpNotFound());
            }
            var products = new MProducts().Get_All().Where(item =>
                                                           item.Category_ID == id).ToList();

            foreach (var item in products)
            {
                item.Producer = new MProducers().Get(item.Producer_ID);
            }

            ViewBag.Products = products;
            return(View(categorie));
        }
Beispiel #6
0
 // GET: Departements
 public ActionResult Index(String Error = "")
 {
     var action = new CheckController().CheckStatus("Departments");
     if (action != null) return action;
     ViewBag.Error = Error;
     return View(db.Get_All());
 }
Beispiel #7
0
        public ActionResult Create(Category category)
        {
            var action = new CheckController().CheckStatus("Categories");

            if (action != null)
            {
                return(action);
            }
            try
            {
                if (ModelState.IsValid)
                {
                    if (String.IsNullOrEmpty(category.Name) ||
                        String.IsNullOrWhiteSpace(category.Name))
                    {
                        throw new Exception($"Cannot Create Category By Empty Name");
                    }
                    db.Add(category);
                    return(RedirectToAction("Index"));
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);
            }
            return(View(category));
        }
        public ActionResult Edit(Order order)
        {
            var action = new CheckController().CheckStatus("Orders");

            if (action != null)
            {
                return(action);
            }
            try
            {
                List <OrderInfo> orderInfos = new List <OrderInfo>();
                float            total      = 0;
                foreach (var item in Products)
                {
                    if (item.OrderQuantity > 0)
                    {
                        orderInfos.Add(item.GetOrderInfo());
                        total += item.PurchasePrice * item.OrderQuantity;
                    }
                }
                order.TotalAmount = total;
                if (orderInfos.Count <= 0)
                {
                    return(View(order));
                }
                db.Update(order, orderInfos);
                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);
            }
            return(View(order));
        }
Beispiel #9
0
        public ActionResult Edit(Pharmacy pharmacy, String NewName)
        {
            var action = new CheckController().CheckStatus("Pharmacy_Info");

            if (action != null)
            {
                return(action);
            }
            if (_Info.Get() != null)
            {
                if (!String.IsNullOrEmpty(NewName))
                {
                    Pharmacy ph = new Pharmacy()
                    {
                        Name = NewName, Email = pharmacy.Email, Address = pharmacy.Address, Phone = pharmacy.Phone
                    };
                    _Info.NewName(ph);
                }
                else
                {
                    _Info.Update(pharmacy);
                }
                Config.CheckData();
            }
            return(RedirectToAction("Index", "Home"));
        }
        // GET: Producers/Create
        public ActionResult Create()
        {
            var action = new CheckController().CheckStatus("Producers");

            if (action != null)
            {
                return(action);
            }
            return(View());
        }
        public ActionResult Index(String ID, int?i)
        {
            var action = new CheckController().CheckStatus("Products");

            if (action != null)
            {
                return(action);
            }
            return(View(GetList(ID)));
        }
Beispiel #12
0
        // GET: Pharmacy/Edit/5
        public ActionResult Edit()
        {
            var action = new CheckController().CheckStatus("Pharmacy_Info");

            if (action != null)
            {
                return(action);
            }
            return(View(_Info.Get()));
        }
        public ActionResult Create(Employee employee, HttpPostedFileBase ImageUrl)
        {
            if (db.Get_All().Count != 0)
            {
                var action = new CheckController().CheckStatus("Employees");
                if (action != null)
                {
                    return(action);
                }
            }
            Config.CheckData();
            try
            {
                if (String.IsNullOrEmpty(employee.NIC) ||
                    String.IsNullOrWhiteSpace(employee.NIC))
                {
                    throw new Exception($"Cannot Create Employee By Empty NIC");
                }

                if (ddb.GetUNDepartment().ID == employee.Department_ID)
                {
                    throw new Exception($"Cannot Create Employee By Empty Or 'Uknown' Department");
                }

                employee.NIC.ToUpper();

                if (ImageUrl != null)
                {
                    if (System.IO.File.Exists($"~/Content/Images/Users/{employee.Picture}"))
                    {
                        System.IO.File.Delete($"~/Content/Images/Users/{employee.Picture}");
                    }

                    var    str       = "";
                    string ImageName = Path.GetFileName(ImageUrl.FileName);
                    do
                    {
                        str = GetName();
                    } while (System.IO.File.Exists($"~/Content/Images/Users/{str}{ImageName}"));
                    string physicalPath = Server.MapPath($"~/Content/Images/Users/{str}{ImageName}");
                    ImageUrl.SaveAs(physicalPath);
                    employee.Picture = $"{str}{ImageName}";
                }
                employee.Password = employee.NIC;
                db.Add(employee);
                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);
            }
            ViewBag.Department_ID = new SelectList(new MDepartments().Get_All()
                                                   .Where(i => i.Title.CompareTo("Unknown") != 0).ToList(), "ID", "Title", employee.Department_ID);
            return(View(employee));
        }
        // GET: Contrats/Create
        public ActionResult Create()
        {
            var action = new CheckController().CheckStatus("ContractTypes");

            if (action != null)
            {
                return(action);
            }
            ViewBag.Employee_ID = new SelectList(new MEmployees().Get_All(), "ID", "NIC");
            return(View());
        }
Beispiel #15
0
        // GET: Categories
        public ActionResult Index(String Error = "")
        {
            var action = new CheckController().CheckStatus("Categories");

            if (action != null)
            {
                return(action);
            }
            ViewBag.Error = Error;
            return(View(db.Get_All()));
        }
        // GET: Orders/Create
        public ActionResult Create()
        {
            var action = new CheckController().CheckStatus("Orders");

            if (action != null)
            {
                return(action);
            }
            FillProductsList();
            return(View());
        }
        // GET: Orders
        public ActionResult Index(String Error = "")
        {
            var action = new CheckController().CheckStatus("Orders");

            if (action != null)
            {
                return(action);
            }
            ViewBag.Error = Error;
            return(View(db.GetPharmacyOrders()));
        }
        // GET: Products
        public ActionResult Index(String Error = "")
        {
            var action = new CheckController().CheckStatus("Products");

            if (action != null)
            {
                return(action);
            }
            ViewBag.Error = Error;
            return(View(GetList("")));
        }
 // GET: Employees/Create
 public ActionResult Create(int t = 0)
 {
     if (t == 0)
     {
         var action = new CheckController().CheckStatus("Employees");
         if (action != null)
         {
             return(action);
         }
     }
     ViewBag.Department_ID = new SelectList(new MDepartments().Get_All()
                                            .Where(i => i.Title.CompareTo("Unknown") != 0).ToList(), "ID", "Title");
     return(View());
 }
        public ActionResult Create()
        {
            var action = new CheckController().CheckStatus("Products");

            if (action != null)
            {
                return(action);
            }
            ViewBag.Category_ID = new SelectList(MC.Get_All().Where(i => i.Name.CompareTo("Unknown") != 0).ToList(),
                                                 "ID", "Name");
            ViewBag.Producer_ID = new SelectList(MP.Get_All().Where(i => i.Name.CompareTo("Unknown") != 0).ToList(),
                                                 "ID", "Name");
            return(View());
        }
        public ActionResult Edit([Bind(Include = "ID,Product_Name,Producer_ID,Price,Quantity,Category_ID")] Product product, HttpPostedFileBase ImageUrl)
        {
            var action = new CheckController().CheckStatus("Products");

            if (action != null)
            {
                return(action);
            }
            try
            {
                if (ModelState.IsValid)
                {
                    Product org = db.Get(product.ID);
                    if (org != null)
                    {
                        product.Picture = org.Picture;
                    }

                    if (ImageUrl != null)
                    {
                        if (System.IO.File.Exists($"~/Content/Images/Products/{org.Picture}"))
                        {
                            System.IO.File.Delete($"~/Content/Images/Products/{org.Picture}");
                        }

                        var    str       = "";
                        string ImageName = Path.GetFileName(ImageUrl.FileName);
                        do
                        {
                            str = GetName();
                        } while (System.IO.File.Exists($"~/Content/Images/Products/{str}{ImageName}"));
                        string physicalPath = Server.MapPath($"~/Content/Images/Products/{str}{ImageName}");
                        ImageUrl.SaveAs(physicalPath);
                        product.Picture = $"{str}{ImageName}";
                    }
                    db.Update(product);
                    return(RedirectToAction("Index"));
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);
            }

            ViewBag.Category_ID = new SelectList(MC.Get_All().Where(i => i.Name.CompareTo("Unknown") != 0).ToList(),
                                                 "ID", "Name", product.Category_ID);
            ViewBag.Producer_ID = new SelectList(MP.Get_All().Where(i => i.Name.CompareTo("Unknown") != 0).ToList(),
                                                 "ID", "Name", product.Producer_ID);
            return(View(product));
        }
Beispiel #22
0
 public ActionResult DeleteConfirmed(int id)
 {
     var action = new CheckController().CheckStatus("Departments");
     if (action != null) return action;
     try
     {
         if (db.GetUNDepartment().ID == id) throw new Exception("Not authorized to delete");
         db.Remove(id);
         return RedirectToAction("Index");
     }
     catch (Exception ex)
     {
         return RedirectToRoute(new { controller = "Departments", action = "Index", Error = ex.Message });
     }
 }
Beispiel #23
0
 // GET: Departements/Edit/5
 public ActionResult Edit(int id)
 {
     var action = new CheckController().CheckStatus("Departments");
     if (action != null) return action;
     if (db.GetUNDepartment().ID == id)
     {
         return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
     }
     Department departement = db.Get(id);
     if (departement == null)
     {
         return HttpNotFound();
     }
     return View(departement);
 }
Beispiel #24
0
 // GET: Pharmacy/Create
 public ActionResult Create(int t = 0)
 {
     if (t == 0)
     {
         var action = new CheckController().CheckStatus("Pharmacy_Info");
         if (action != null)
         {
             return(action);
         }
     }
     if (_Info.Get() != null)
     {
         return(RedirectToAction("Edit"));
     }
     return(View());
 }
        public ActionResult Edit(Employee employee, HttpPostedFileBase ImageUrl)
        {
            var action = new CheckController().CheckStatus("Employees");

            if (action != null)
            {
                return(action);
            }
            try
            {
                if (ModelState.IsValid)
                {
                    if (ddb.GetUNDepartment().ID == employee.Department_ID)
                    {
                        throw new Exception($"Cannot Update Department's Employee To Empty Or 'Uknown' Department");
                    }

                    if (ImageUrl != null)
                    {
                        if (System.IO.File.Exists($"~/Content/Images/Users/{employee.Picture}"))
                        {
                            System.IO.File.Delete($"~/Content/Images/Users/{employee.Picture}");
                        }

                        var    str       = "";
                        string ImageName = Path.GetFileName(ImageUrl.FileName);
                        do
                        {
                            str = GetName();
                        } while (System.IO.File.Exists($"~/Content/Images/Users/{str}{ImageName}"));
                        string physicalPath = Server.MapPath($"~/Content/Images/Users/{str}{ImageName}");
                        ImageUrl.SaveAs(physicalPath);
                        employee.Picture = $"{str}{ImageName}";
                    }
                    db.Update(employee);
                    return(RedirectToAction("Index"));
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);
            }
            ViewBag.Department_ID = new SelectList(new MDepartments().Get_All()
                                                   .Where(i => i.Title.CompareTo("Unknown") != 0).ToList(), "ID", "Title", employee.Department_ID);
            return(View(employee));
        }
        public ActionResult Index(String Error = "")
        {
            var action = new CheckController().CheckStatus("ContractTypes");

            if (action != null)
            {
                return(action);
            }
            ViewBag.Error = Error;
            var list = db.Get_All();

            foreach (var item in list)
            {
                item.Employee = new MEmployees().Get(item.Employee_ID);
            }
            return(View(list));
        }
        public ActionResult Edit([Bind(Include = "ID,Employee_ID,Type,Start,Document")] Contract contract
                                 , HttpPostedFileBase Document)
        {
            var action = new CheckController().CheckStatus("ContractTypes");

            if (action != null)
            {
                return(action);
            }
            try
            {
                if (new MEmployees().Get(contract.Employee_ID) == null)
                {
                    throw new Exception($"Cannot Find The Employee");
                }

                if (Document != null)
                {
                    if (System.IO.File.Exists($"~/Content/Documents/{contract.Document}"))
                    {
                        System.IO.File.Delete($"~/Content/Documents/{contract.Document}");
                    }

                    var    str      = "";
                    string fileName = Path.GetFileName(Document.FileName);
                    do
                    {
                        str = GetName();
                    } while (System.IO.File.Exists($"~/Content/Documents/{str}{fileName}"));

                    string physicalPath = Server.MapPath($"~/Content/Documents/{str}{fileName}");
                    Document.SaveAs(physicalPath);
                    contract.Document = $"{str}{fileName}";
                }

                db.Update(contract);
                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);
            }
            ViewBag.Employee_ID = new SelectList(new MEmployees().Get_All(), "ID", "NIC", contract.Employee_ID);
            return(View(contract));
        }
        public ActionResult DeleteConfirmed(String ID, Boolean SubtractQuantity = false)
        {
            var action = new CheckController().CheckStatus("Orders");

            if (action != null)
            {
                return(action);
            }
            try
            {
                db.Delete(ID, SubtractQuantity);
                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                return(RedirectToRoute(new { action = "Index", Error = ex.Message }));
            }
        }
        public ActionResult DeleteConfirmed(string id)
        {
            var action = new CheckController().CheckStatus("Products");

            if (action != null)
            {
                return(action);
            }
            try
            {
                db.Delete(id);
                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                return(RedirectToRoute(new { controller = "Products", action = "Index", Error = ex.Message }));
            }
        }
        public ActionResult DeleteConfirmed(int ID)
        {
            var action = new CheckController().CheckStatus("Employees");

            if (action != null)
            {
                return(action);
            }
            try
            {
                db.Remove(ID);
                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                return(RedirectToRoute(new { action = "Index", Error = ex.Message }));
            }
        }