//[ValidateAntiForgeryToken] public HttpStatusCodeResult NewMembershipAccount(int CustomerId, int MembershipTypeId) { try { using (PharmAssistantContext db = new PharmAssistantContext()) { MembershipAccount membershipAccount = new MembershipAccount { CustomerId = CustomerId, MembershipTypeId = MembershipTypeId, JoiningDate = DateTime.Now }; db.MembershipAccounts.Add(membershipAccount); db.SaveChanges(); Customer customer = db.Customers.Where(c => c.CustomerId == CustomerId).FirstOrDefault(); customer.MembershipId = db.MembershipAccounts.Where(ma => ma.CustomerId == CustomerId).FirstOrDefault().MembershipId; db.Customers.Attach(customer); db.Entry(customer).State = EntityState.Modified; db.SaveChanges(); } return(new HttpStatusCodeResult(HttpStatusCode.OK)); } catch (Exception ex) { Console.WriteLine(ex.Message); return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } }
public ActionResult ReceiveOrder(string OrderId, ICollection <long> BatchNumbers, ICollection <DateTime> ExpiryDates) { using (PharmAssistantContext db = new PharmAssistantContext()) { try { db.Database.BeginTransaction(); PurchaseOrder order = db.PurchaseOrders.Where(o => o.PurchaseOrderId == OrderId).FirstOrDefault(); ICollection <PurchaseOrderItem> OrderItems = db.PurchaseOrderItems.Where(i => i.PurchaseOrderId == OrderId).ToList(); StockEntry stockEntry; order.OrderStatus = true; long[] batchNumbers = BatchNumbers.ToArray(); DateTime[] expiryDates = ExpiryDates.ToArray(); int counter = 0; foreach (var OrderItem in OrderItems) { OrderItem.BatchNumber = batchNumbers[counter]; OrderItem.ExpiryDate = expiryDates[counter++]; db.PurchaseOrderItems.Attach(OrderItem); db.Entry(OrderItem).State = EntityState.Modified; stockEntry = new StockEntry { MedicineId = OrderItem.MedicineId, PurchaseOrderId = OrderItem.PurchaseOrderId, BatchNumber = OrderItem.BatchNumber.ToString(), Quantity = OrderItem.Quantity, CostPrice = OrderItem.CostPrice, SellingPrice = OrderItem.SellingPrice, ExpiryDate = OrderItem.ExpiryDate }; db.StockEntries.Add(stockEntry); } db.SaveChanges(); db.PurchaseOrders.Attach(order); db.Entry(order).State = EntityState.Modified; db.SaveChanges(); db.Database.CurrentTransaction.Commit(); } catch (Exception ex) { Console.WriteLine(ex.Message); db.Database.CurrentTransaction.Rollback(); } } return(RedirectToAction("PurchaseOrdersList")); }
public ActionResult UpdateInventorySetting(Medicine medicine) { try { if (medicine.StockCapacity == 0 || medicine.ReorderLevel == 0 || medicine.BufferLevel == 0) { return(Json("Invalid Data", JsonRequestBehavior.AllowGet)); } using (PharmAssistantContext db = new PharmAssistantContext()) { db.Medicines.Attach(medicine); //db.Entry(medicine).State = EntityState.Modified; db.Entry(medicine).Property("StockCapacity").IsModified = true; db.Entry(medicine).Property("ReorderLevel").IsModified = true; db.Entry(medicine).Property("BufferLevel").IsModified = true; db.SaveChanges(); } } catch (Exception ex) { Console.WriteLine(ex.Message); return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } //TempData["UpdateSuccess"] = "Record updated successfully."; //return RedirectToAction("AvailableStock"); return(Json(GetInventorySettings(), JsonRequestBehavior.AllowGet)); }
public ActionResult UpdateMedicine(Medicine Medicine) { if (ModelState.IsValid) { try { using (PharmAssistantContext db = new PharmAssistantContext()) { db.Medicines.Attach(Medicine); db.Entry(Medicine).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("MedicinesList")); } } catch (Exception ex) { Console.WriteLine(ex.Message); ViewBag.ErrorMessage = "Unable to edit medicine."; return(View("EditMedicine", Medicine)); } } else { FillDropdowns(); return(View("EditMedicine", Medicine)); } }
public ActionResult AddManufacturer(Manufacturer manufacturer) { if (ModelState.IsValid) { try { using (PharmAssistantContext db = new PharmAssistantContext()) { db.Manufacturers.Add(manufacturer); db.SaveChanges(); } } catch (Exception ex) { Console.WriteLine(ex.Message); } return(PartialView("_ManufacturersList", GetAllManufacturers())); //return View("Index", new ManufacturerViewModel { Manufacturer = new Manufacturer(), ManufacturersList = GetAllManufacturers()}); //return RedirectToAction("Index"); } else { ModelState.AddModelError("Name", "Invalid Name"); //return PartialView("_ManufacturersList", GetAllManufacturers()); //return View("Index", new ManufacturerViewModel { Manufacturer = new Manufacturer(), ManufacturersList = GetAllManufacturers() }); return(RedirectToAction("Index")); } }
public ActionResult AssociateSuppliersToMedicine(MedicineSupplierViewModel MedicineSupplierData) { Console.WriteLine(MedicineSupplierData); using (PharmAssistantContext db = new PharmAssistantContext()) { try { Medicine medicine = db.Medicines.Where(m => m.MedicineId == MedicineSupplierData.MedicineId).FirstOrDefault(); var suppliers = db.Suppliers; foreach (var supplier in suppliers) { if (MedicineSupplierData.SelectedSuppliersForMedicine.Contains(supplier.SupplierId) && !medicine.Suppliers.Contains(supplier)) { medicine.Suppliers.Add(supplier); } else if (!MedicineSupplierData.SelectedSuppliersForMedicine.Contains(supplier.SupplierId) && medicine.Suppliers.Contains(supplier)) { medicine.Suppliers.Remove(supplier); } } db.SaveChanges(); } catch (Exception ex) { Console.WriteLine(ex.Message); } } return(RedirectToAction("ManageSuppliers")); }
public ActionResult AddShelf(Shelf Shelf) { try { using (PharmAssistantContext db = new PharmAssistantContext()) { var existingShelf = db.Shelves.Where(s => s.ShelfName == Shelf.ShelfName && s.ShelfId == Shelf.ShelfId).FirstOrDefault(); if (existingShelf == null) { db.Shelves.Add(Shelf); db.SaveChanges(); return(PartialView("_ShelvesList", db.Shelves.ToList())); } else { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, "Shelf Already Exists.")); } } } catch (Exception ex) { Console.WriteLine(ex.Message); return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, "Something went wrong. Please try again later.")); } }
public ActionResult AddCategory(MedicineCategory Category) { try { using (PharmAssistantContext db = new PharmAssistantContext()) { var existingCategory = db.MedicineCategories.Where(c => c.MedicineCategoryName == Category.MedicineCategoryName).FirstOrDefault(); if (existingCategory == null) { db.MedicineCategories.Add(Category); db.SaveChanges(); return(PartialView("_MedicineCategoryList", GetAllCategories())); } else { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, "Categoty Already Exists.")); } } } catch (Exception ex) { Console.WriteLine(ex.Message); return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, "Something went wrong. Please try again later.")); } }
public ActionResult AddCustomer(Customer customer) { if (ModelState.IsValid) { try { using (PharmAssistantContext db = new PharmAssistantContext()) { db.Customers.Add(customer); db.SaveChanges(); TempData["SuccessMessage"] = "Customer added successfully"; return(RedirectToAction("Index")); } } catch (Exception ex) { Console.WriteLine(ex.Message); TempData["ErrorMessage"] = "Unable to add customer. Please try again later."; return(RedirectToAction("Index")); } } else { return(View("NewCustomer", customer)); } }
public ActionResult UpdateSupplier(Supplier supplier) { if (ModelState.IsValid) { try { using (PharmAssistantContext db = new PharmAssistantContext()) { db.Suppliers.Attach(supplier); db.Entry(supplier).State = EntityState.Modified; db.SaveChanges(); } } catch (Exception ex) { Console.WriteLine(ex.Message); } return(PartialView("_SuppliersList", GetAllSuppliers())); //return View("Index", new SupplierViewModel { Supplier = new Supplier(), SuppliersList = GetAllSuppliers()}); //return RedirectToAction("Index"); } else { ModelState.AddModelError("Name", "Invalid Name"); //return PartialView("_SuppliersList", GetAllSuppliers()); //return View("Index", new SupplierViewModel { Supplier = new Supplier(), SuppliersList = GetAllSuppliers() }); return(RedirectToAction("Index")); } }
public ActionResult SavePurchaseOrder(PurchaseOrderViewModel PurchaseOrderModel) { double OrderCost = 0; ICollection <PurchaseOrderItem> OrderItems = ((PurchaseOrderViewModel)Session["PurchaseOrderModel"]).PurchaseOrderItems; foreach (var item in OrderItems) { item.PurchaseOrderId = Session["PurchaseOrderId"].ToString(); OrderCost += item.Quantity * item.SellingPrice; } PurchaseOrderModel.PurchaseOrderItems = OrderItems; PurchaseOrderModel.PurchaseOrder.OrderCost = Math.Round(OrderCost, 2); using (PharmAssistantContext db = new PharmAssistantContext()) { try { db.Database.BeginTransaction(); db.PurchaseOrders.Add(PurchaseOrderModel.PurchaseOrder); db.SaveChanges(); db.PurchaseOrderItems.AddRange(PurchaseOrderModel.PurchaseOrderItems); db.SaveChanges(); db.Database.CurrentTransaction.Commit(); } catch (Exception ex) { Console.WriteLine(ex.Message); db.Database.CurrentTransaction.Rollback(); FillDropdowns(); return(View("NewPurchaseOrder", PurchaseOrderModel)); throw; } } return(RedirectToAction("PurchaseOrdersList")); }
public ActionResult DeleteCategory(long Id) { try { using (PharmAssistantContext db = new PharmAssistantContext()) { MedicineCategory existingCategory = db.MedicineCategories.Where(c => c.CategoryId == Id).FirstOrDefault(); db.MedicineCategories.Remove(existingCategory); db.SaveChanges(); } } catch (Exception ex) { Console.WriteLine(ex.Message); } return(RedirectToAction("MedicineCategories")); }
public ActionResult DeleteMedicine(int MedicineId) { try { using (PharmAssistantContext db = new PharmAssistantContext()) { db.Medicines.Remove(db.Medicines.Where(m => m.MedicineId == MedicineId).FirstOrDefault()); db.SaveChanges(); } } catch (Exception ex) { Console.WriteLine(ex.Message); } return(RedirectToAction("MedicinesList")); }
public ActionResult DeleteShelf(int Id) { try { using (PharmAssistantContext db = new PharmAssistantContext()) { Shelf shelf = db.Shelves.Where(s => s.ShelfId == Id).FirstOrDefault(); db.Shelves.Remove(shelf); db.SaveChanges(); } } catch (Exception ex) { Console.WriteLine(ex.Message); } return(RedirectToAction("ShelvesList")); }
//[ValidateAntiForgeryToken] public HttpStatusCodeResult DeleteMembershipType(int membershipTypeId) { try { using (PharmAssistantContext db = new PharmAssistantContext()) { db.MembershipTypes.Remove(db.MembershipTypes.Where(mt => mt.MembershipTypeId == membershipTypeId).FirstOrDefault()); db.SaveChanges(); return(new HttpStatusCodeResult(HttpStatusCode.OK)); } } catch (Exception ex) { Console.WriteLine(ex.Message); return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } }
//[ValidateAntiForgeryToken] public HttpStatusCodeResult AddMembershipType(MembershipType membershipType) { try { using (PharmAssistantContext db = new PharmAssistantContext()) { db.MembershipTypes.Add(membershipType); db.SaveChanges(); } return(new HttpStatusCodeResult(HttpStatusCode.OK)); } catch (Exception ex) { Console.WriteLine(ex.Message); return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } }
public ActionResult AddMedicine(Medicine Medicine) { try { using (PharmAssistantContext db = new PharmAssistantContext()) { db.Medicines.Add(Medicine); db.SaveChanges(); return(RedirectToAction("MedicinesList")); } } catch (Exception ex) { Console.WriteLine(ex.Message); ViewBag.ErrorMessage = "Unable to add medicine. Try again later."; return(View("NewMedicine", Medicine)); } }
public ActionResult DeleteCustomer(int CustomerId) { try { using (PharmAssistantContext db = new PharmAssistantContext()) { db.Customers.Remove(db.Customers.Where(c => c.CustomerId == CustomerId).FirstOrDefault()); db.SaveChanges(); TempData["SuccessMessage"] = "Customer deleted successfully"; return(RedirectToAction("Index")); } } catch (Exception ex) { Console.WriteLine(ex.Message); TempData["ErrorMessage"] = "Unable to delete customer. Please try again later."; return(RedirectToAction("Index")); } }
public ActionResult UpdateCustomer(Customer customer) { try { using (PharmAssistantContext db = new PharmAssistantContext()) { db.Customers.Attach(customer); db.Entry(customer).State = EntityState.Modified; db.SaveChanges(); TempData["SuccessMessage"] = "Customer updated successfully"; return(RedirectToAction("Index")); } } catch (Exception ex) { Console.WriteLine(ex.Message); TempData["ErrorMessage"] = "Unable to update customer. Please try again later."; return(RedirectToAction("Index")); } }
public ActionResult DeleteManufacturer(int Id) { using (PharmAssistantContext db = new PharmAssistantContext()) { try { Manufacturer manufacturer = db.Manufacturers.Where(m => m.ManufacturerId == Id).FirstOrDefault(); if (manufacturer != null) { db.Manufacturers.Remove(manufacturer); db.SaveChanges(); } } catch (Exception ex) { Console.WriteLine("Excption while deletion of Manufacturer: " + ex.Message); } } return(RedirectToAction("Index")); }
//[ValidateAntiForgeryToken] public HttpStatusCodeResult UpdateMembershipType(MembershipType membershipType) { try { using (PharmAssistantContext db = new PharmAssistantContext()) { db.MembershipTypes.Attach(membershipType); db.Entry(membershipType).Property("MembershipTypeName").IsModified = true; db.Entry(membershipType).Property("MembershipTypeDesc").IsModified = true; db.Entry(membershipType).Property("UpperBillLimit").IsModified = true; db.Entry(membershipType).Property("BonusPoints").IsModified = true; db.SaveChanges(); return(new HttpStatusCodeResult(HttpStatusCode.OK)); } } catch (Exception ex) { Console.WriteLine(ex.Message); return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } }
public ActionResult DeleteOrder(string OrderId) { using (PharmAssistantContext db = new PharmAssistantContext()) { try { db.Database.BeginTransaction(); db.PurchaseOrderItems.RemoveRange(db.PurchaseOrderItems.Where(i => i.PurchaseOrderId == OrderId)); db.PurchaseOrders.RemoveRange(db.PurchaseOrders.Where(o => o.PurchaseOrderId == OrderId)); db.SaveChanges(); db.Database.CurrentTransaction.Commit(); } catch (Exception ex) { Console.WriteLine(ex.Message); db.Database.CurrentTransaction.Rollback(); throw; } } return(RedirectToAction("PurchaseOrdersList")); }
//[ValidateAntiForgeryToken] public HttpStatusCodeResult UpdateMembershipAccount(int MembershipId, int MembershipTypeId) { try { using (PharmAssistantContext db = new PharmAssistantContext()) { var membershipAccount = db.MembershipAccounts.Where(a => a.MembershipId == MembershipId).FirstOrDefault(); membershipAccount.MembershipTypeId = MembershipTypeId; db.MembershipAccounts.Attach(membershipAccount); db.Entry(membershipAccount).Property("MembershipTypeId").IsModified = true; //db.Entry(membershipAccount).Property("TotalPurchaseAmount").IsModified = true; //db.Entry(membershipAccount).Property("BonusPoints").IsModified = true; db.SaveChanges(); return(new HttpStatusCodeResult(HttpStatusCode.OK)); } } catch (Exception ex) { Console.WriteLine(ex.Message); return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } }
public ActionResult UpdatePurchaseOrder(PurchaseOrderViewModel PurchaseOrderModel) { double OrderCost = 0; ICollection <PurchaseOrderItem> OrderItems = ((PurchaseOrderViewModel)Session["PurchaseOrderModel"]).PurchaseOrderItems; foreach (var item in OrderItems) { //item.PurchaseOrderId = Session["PurchaseOrderId"].ToString(); if (item.PurchaseOrderId == null) { item.PurchaseOrderId = PurchaseOrderModel.PurchaseOrder.PurchaseOrderId; } OrderCost += item.Quantity * item.SellingPrice; } PurchaseOrderModel.PurchaseOrderItems = OrderItems; PurchaseOrderModel.PurchaseOrder.OrderCost = Math.Round(OrderCost, 2); PurchaseOrderModel.PurchaseOrder.AmountPaid = Math.Round(OrderCost, 2) - PurchaseOrderModel.PurchaseOrder.Discount; using (PharmAssistantContext db = new PharmAssistantContext()) { var UpdatedOrder = db.PurchaseOrders.Include("Supplier").Where(o => o.PurchaseOrderId == PurchaseOrderModel.PurchaseOrder.PurchaseOrderId).FirstOrDefault(); try { db.Database.BeginTransaction(); UpdatedOrder.Remarks = PurchaseOrderModel.PurchaseOrder.Remarks; UpdatedOrder.PaymentStatus = PurchaseOrderModel.PurchaseOrder.PaymentStatus; UpdatedOrder.OrderCost = PurchaseOrderModel.PurchaseOrder.OrderCost; UpdatedOrder.AmountPaid = PurchaseOrderModel.PurchaseOrder.AmountPaid; db.PurchaseOrders.Attach(UpdatedOrder); db.Entry(UpdatedOrder).State = EntityState.Modified; db.SaveChanges(); foreach (var Item in OrderItems) { if (db.PurchaseOrderItems.Where(pi => pi.PurchaseOrderId == Item.PurchaseOrderId && pi.MedicineId == Item.MedicineId).FirstOrDefault() == null) { //db.PurchaseOrderItems.Attach(Item); //db.Entry(Item).State = EntityState.Modified; db.PurchaseOrderItems.Add(Item); } } db.SaveChanges(); db.Database.CurrentTransaction.Commit(); } catch (Exception ex) { Console.WriteLine(ex.Message); db.Database.CurrentTransaction.Rollback(); ViewBag.MedicineCategories = new SelectList(db.MedicineCategories.Where(m => m.Suppliers.Contains(db.Suppliers.Where(s => s.SupplierId == PurchaseOrderModel.PurchaseOrder.SupplierId).FirstOrDefault())).ToList(), "CategoryId", "MedicineCategoryName"); PurchaseOrderModel.PurchaseOrderItems = OrderItems; PurchaseOrderModel.PurchaseOrder.Supplier = UpdatedOrder.Supplier; PurchaseOrderModel.PurchaseOrder.PurchaseOrderCode = UpdatedOrder.PurchaseOrderCode; PurchaseOrderModel.PurchaseOrder.PurchaseDate = UpdatedOrder.PurchaseDate; PurchaseOrderModel.PurchaseOrder.PaymentMode = UpdatedOrder.PaymentMode; PurchaseOrderModel.PurchaseOrder.Discount = UpdatedOrder.Discount; PurchaseOrderModel.PurchaseOrder.AmountPaid = UpdatedOrder.AmountPaid; return(View("EditOrder", PurchaseOrderModel)); } } return(RedirectToAction("PurchaseOrdersList")); }