Beispiel #1
0
        public ActionResult Create([Bind(Include = "MedPot_Id,Medicine_Id,Potency_Id,Price,ExpiryDate,NoOfItem")] MedicinePotency medicinePotency)
        {
            if (ModelState.IsValid)
            {
                MedicinePotency meddpot = db.MedicinePotencies.FirstOrDefault(u => u.Medicine_Id == (medicinePotency.Medicine_Id) && u.Potency_Id == medicinePotency.Potency_Id);

                if (meddpot == null)
                {
                    db.MedicinePotencies.Add(medicinePotency);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                else
                {
                    ModelState.AddModelError("Medicine_Id", "Medicine with given potency is alredy present in Record.");
                    ViewBag.Medicine_Id = new SelectList(db.Medicines, "Medicine_Id", "Name", medicinePotency.Medicine_Id);
                    ViewBag.Potency_Id  = new SelectList(db.Potencies, "Potency_Id", "Potency_Id", medicinePotency.Potency_Id);
                    return(View(medicinePotency));
                }
            }

            ViewBag.Medicine_Id = new SelectList(db.Medicines, "Medicine_Id", "Name", medicinePotency.Medicine_Id);
            ViewBag.Potency_Id  = new SelectList(db.Potencies, "Potency_Id", "Potency_Id", medicinePotency.Potency_Id);
            return(View(medicinePotency));
        }
        public ActionResult Create([Bind(Include = "Medicine_Id,Name,Description,ExpiryDate,CategoryID,SupplierID")] Medicine medicine)
        {
            Medicine medicines = db.Medicines.FirstOrDefault(u => u.Name == medicine.Name);

            if (ModelState.IsValid)
            {
                if (medicines == null)
                {
                    db.Medicines.Add(medicine);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                else
                {
                    ModelState.AddModelError("Name", "Medicine with same name is Alredy Present.");
                    ViewBag.CategoryID = new SelectList(db.Categories, "Category_Id", "Category_Name", medicine.CategoryID);
                    ViewBag.SupplierID = new SelectList(db.Suppliers, "SupplierID", "CompanyName", medicine.SupplierID);
                    return(View(medicine));
                }
            }

            ViewBag.CategoryID = new SelectList(db.Categories, "Category_Id", "Category_Name", medicine.CategoryID);
            ViewBag.SupplierID = new SelectList(db.Suppliers, "SupplierID", "CompanyName", medicine.SupplierID);
            return(View(medicine));
        }
        public ActionResult Create([Bind(Include = "SupplierID,CompanyName,ContactName,ContactTitle,Address,City,Country,Fax")] Supplier supplier)
        {
            if (ModelState.IsValid)
            {
                db.Suppliers.Add(supplier);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(supplier));
        }
Beispiel #4
0
        public ActionResult Create([Bind(Include = "Customer_Id,Customer_Name,Contact,Address,Added_On")] Customer customer)
        {
            if (ModelState.IsValid)
            {
                db.Customers.Add(customer);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(customer));
        }
Beispiel #5
0
        public ActionResult SignUp([Bind(Include = "FirstName,LastName,Contact,Email,Address,Country,DateOfBirth,Gender,Discriminator,Password,ConfirmPassword ")] User userrr)
        {
            using (DB53Entities db = new DB53Entities())
            {
                Person persuser = db.People.FirstOrDefault(u => u.Email == (userrr.Email));
                if (userrr.Discriminator == "Admin")
                {
                    Login oldlog = db.Logins.FirstOrDefault(u => u.Discriminator == userrr.Discriminator);
                    if (oldlog != null)
                    {
                        ModelState.AddModelError("Discriminator", "Admin is alredy present. There can be only one Admin.");
                        return(View(userrr));
                    }
                }
                if (persuser == null)
                {
                    Person pers = new Person();
                    pers.Address     = userrr.Address;
                    pers.Contact     = userrr.Contact;
                    pers.Country     = userrr.Country;
                    pers.DateOfBirth = userrr.DateOfBirth;
                    pers.Email       = userrr.Email;
                    pers.FirstName   = userrr.FirstName;
                    pers.LastName    = userrr.LastName;
                    pers.Gender      = userrr.Gender;

                    db.People.Add(pers);
                    db.SaveChanges();
                    Person user = db.People.FirstOrDefault(newuser => newuser.Email == (userrr.Email));

                    Login newlog = new Login();
                    newlog.Login_Id      = user.Id;
                    newlog.Email         = userrr.Email;
                    newlog.Password      = userrr.Password;
                    newlog.Discriminator = userrr.Discriminator;
                    db.Logins.Add(newlog);
                    db.SaveChanges();
                    return(RedirectToAction("Index", "People"));
                }
                else
                {
                    return(View());
                }
            }
        }
        public ActionResult Create([Bind(Include = "Category_Id,Category_Name,Discription")] Category category)
        {
            if (ModelState.IsValid)
            {
                Category cat = db.Categories.FirstOrDefault(u => u.Category_Name == category.Category_Name);
                if (cat == null)
                {
                    db.Categories.Add(category);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                else
                {
                    ModelState.AddModelError("Category_Name", "Category already added");
                    return(View(category));
                }
            }

            return(View(category));
        }
Beispiel #7
0
        public ActionResult Create([Bind(Include = "Staff_Id,Salary,Designation")] Staff staff)
        {
            if (ModelState.IsValid)
            {
                Staff user = db.Staffs.FirstOrDefault(u => u.Staff_Id == staff.Staff_Id);
                if (user == null)
                {
                    db.Staffs.Add(staff);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                else
                {
                    ModelState.AddModelError("Staff_Id", "Staff Already Added.");
                    ViewBag.Staff_Id = new SelectList(db.People, "Id", "FirstName", staff.Staff_Id);
                    return(View(staff));
                }
            }

            ViewBag.Staff_Id = new SelectList(db.People, "Id", "FirstName", staff.Staff_Id);
            return(View(staff));
        }
Beispiel #8
0
        public ActionResult Create([Bind(Include = "Sold_Id,NoOfItem,Date,Staff_Id,Customer_Id,Medicine_Id,Potency_Id")] SalesObjectclass salesobj)
        {
            Sale            sale   = new Sale();
            MedicinePotency medpot = db.MedicinePotencies.FirstOrDefault(u => u.Medicine_Id == salesobj.Medicine_Id && u.Potency_Id == salesobj.Potency_Id);

            if (medpot != null)
            {
                if (medpot.NoOfItem >= salesobj.NoOfItem)
                {
                    if (ModelState.IsValid)
                    {
                        sale.MedPot_Id   = medpot.MedPot_Id;
                        sale.NoOfItem    = salesobj.NoOfItem;
                        sale.Staff_Id    = salesobj.Staff_Id;
                        sale.Date        = salesobj.Date;
                        sale.Customer_Id = salesobj.Customer_Id;


                        db.Sales.Add(sale);
                        db.SaveChanges();
                        medpot.NoOfItem        = (medpot.NoOfItem) - (salesobj.NoOfItem);
                        db.Entry(medpot).State = EntityState.Modified;
                        db.SaveChanges();
                        return(RedirectToAction("Index"));
                    }
                }
                else
                {
                    ModelState.AddModelError("NoOfItem", "Medicine is out of stock.");
                    ViewBag.Customer_Id = new SelectList(db.Customers, "Customer_Id", "Customer_Name", salesobj.Customer_Id);
                    ViewBag.Medicine_Id = new SelectList(db.Medicines, "Medicine_Id", "Name", salesobj.Medicine_Id);
                    ViewBag.Potency_Id  = new SelectList(db.Potencies, "Potency_Id", "Potency_mg", salesobj.Potency_Id);
                    ViewBag.Staff_Id    = new SelectList(db.People, "Id", "FirstName", salesobj.Staff_Id);
                    return(View(salesobj));
                }
            }
            ViewBag.Customer_Id = new SelectList(db.Customers, "Customer_Id", "Customer_Name", salesobj.Customer_Id);
            ViewBag.Medicine_Id = new SelectList(db.Medicines, "Medicine_Id", "Name", salesobj.Medicine_Id);
            ViewBag.Potency_Id  = new SelectList(db.Potencies, "Potency_Id", "Potency_mg", salesobj.Potency_Id);
            ViewBag.Staff_Id    = new SelectList(db.People, "Id", "FirstName", salesobj.Staff_Id);
            return(View(salesobj));
        }
Beispiel #9
0
        public ActionResult Create([Bind(Include = "Id,FirstName,LastName,Contact,Email,Address,Country,DateOfBirth,Gender,Discriminator")] Person person)
        {
            string pass    = "******";
            Login  newuser = new Login();

            newuser.Login_Id      = person.Id;
            newuser.Password      = pass;
            newuser.Email         = person.Email;
            newuser.Discriminator = "Admin";
            if (ModelState.IsValid)
            {
                db.People.Add(person);
                db.Logins.Add(newuser);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.Id = new SelectList(db.Logins, "Login_Id", "Email", person.Id);
            ViewBag.Id = new SelectList(db.Staffs, "Staff_Id", "Designation", person.Id);
            return(View(person));
        }