public ActionResult Create(MedicineItem items, MedicineCategory medicineCategory, IFormFile[] Image) { try { if (Image != null) { if (medicineCategory.MedicineItems.Count == Image.Count()) { for (int i = 0; i < medicineCategory.MedicineItems.Count; i++) { string picture = System.IO.Path.GetFileName(Image[i].FileName); var file = picture; var uploadFile = Path.Combine(_hostingEnvironment.WebRootPath, "images", picture); using (MemoryStream ms = new MemoryStream()) { Image[i].CopyTo(ms); medicineCategory.MedicineItems[i].Image = ms.GetBuffer(); } } } _context.MedicineCategories.Add(medicineCategory); _context.SaveChanges(); TempData["id"] = medicineCategory.ID; return(RedirectToAction("Index")); } return(View(medicineCategory)); } catch (Exception) { return(View(medicineCategory)); } }
public async Task <IActionResult> Edit(int id, [Bind("Id,Name")] MedicineCategory medicineCategory) { if (id != medicineCategory.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(medicineCategory); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MedicineCategoryExists(medicineCategory.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(medicineCategory)); }
private BaseItem createTestItem(string illness) { PlayerInventory mockPlayerInventory = new PlayerInventory("player", 20); PlayerController controller = new GameObject().AddComponent <PlayerController>(); controller.PlayerStatManager = new PlayerStatManager(); Game.Instance.PlayerInstance = new Player(mockPlayerInventory); Game.Instance.PlayerInstance.Controller = controller; BaseItem medicineItem = new BaseItem("Sample Medicine"); medicineItem.FlavorText = "This is a test medicine"; medicineItem.InventorySprite = "medicine.png"; medicineItem.WorldModel = "medicineModel.png"; medicineItem.Types = new List <string>(); medicineItem.Types.Add(ItemTypes.Medicinal); MedicineCategory medicine = new MedicineCategory(); medicine.HealthGain = 5f; medicine.Sickness = illness; medicineItem.AddItemCategory(medicine); return(medicineItem); }
public ActionResult AssociateSuppliersToCategory(MedicineSupplierViewModel MedicineSupplierData) { Console.WriteLine(MedicineSupplierData); using (PharmAssistantContext db = new PharmAssistantContext()) { try { MedicineCategory category = db.MedicineCategories.Where(c => c.CategoryId == MedicineSupplierData.CategoryId).FirstOrDefault(); var suppliers = db.Suppliers; foreach (var supplier in suppliers) { if (MedicineSupplierData.SelectedSuppliersForCategory.Contains(supplier.SupplierId) && !category.Suppliers.Contains(supplier)) { category.Suppliers.Add(supplier); } else if (!MedicineSupplierData.SelectedSuppliersForCategory.Contains(supplier.SupplierId) && category.Suppliers.Contains(supplier)) { category.Suppliers.Remove(supplier); } } db.SaveChanges(); } catch (Exception ex) { Console.WriteLine(ex.Message); } } return(RedirectToAction("ManageSuppliers")); }
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 async Task <IActionResult> Create([Bind("Id,Name")] MedicineCategory medicineCategory) { if (ModelState.IsValid) { _context.Add(medicineCategory); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(medicineCategory)); }
public void CureFoodPoisoningTest() { BaseItem medicineItem = createTestItem("food poisoning"); Game.Instance.PlayerInstance.HealthStatus = PlayerHealthStatus.FoodPoisoning; MedicineCategory medicineCategory = (MedicineCategory)medicineItem.GetItemCategoryByClass(typeof(MedicineCategory)); //Act medicineCategory.CureFoodPoisoning(); Assert.AreEqual(Game.Instance.PlayerInstance.HealthStatus, PlayerHealthStatus.None); }
//public ActionResult Edit(long? id) //{ // if (id == null) // { // return NotFound(); // } // var medicineCategory = _context.MedicineCategories.FindAsync(id); // if (medicineCategory == null) // { // return NotFound(); // } // return PartialView(medicineCategory); //} //[HttpPost] //[ValidateAntiForgeryToken] //public ActionResult Edit(MedicineItem items, MedicineCategory medicineCategory, IFormFile[] Image) //{ // try // { // if (Image != null) // { // if (medicineCategory.MedicineItems.Count == Image.Count()) // { // for (int i = 0; i < medicineCategory.MedicineItems.Count; i++) // { // string picture = System.IO.Path.GetFileName(Image[i].FileName); // var file = picture; // var uploadFile = Path.Combine(_hostingEnvironment.WebRootPath, "images", picture); // using (MemoryStream ms = new MemoryStream()) // { // Image[i].CopyTo(ms); // medicineCategory.MedicineItems[i].Image = ms.GetBuffer(); // } // } // } // _context.MedicineCategories.Add(medicineCategory); // _context.Entry(medicineCategory).State = EntityState.Modified; // _context.SaveChanges(); // TempData["id"] = medicineCategory.ID; // return RedirectToAction("Index"); // } // return View(medicineCategory); // } // catch (Exception) // { // return View(medicineCategory); // } //} public IActionResult Delete(long id) { MedicineCategory medicineCategory = _context.MedicineCategories.Find(id); if (medicineCategory != null) { _context.MedicineCategories.Remove(medicineCategory); _context.SaveChanges(); return(RedirectToAction("Index")); } return(RedirectToAction("Index")); }
public void CurePneumoniaTest() { BaseItem medicineItem = createTestItem("pneumonia"); Game.Instance.PlayerInstance.HealthStatus = PlayerHealthStatus.Pneumonia; MedicineCategory medicineCategory = (MedicineCategory)medicineItem.GetItemCategoryByClass(typeof(MedicineCategory)); //Act medicineCategory.CurePneumonia(); Assert.AreEqual(Game.Instance.PlayerInstance.HealthStatus, PlayerHealthStatus.None); }
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 void HealTest() { // Arrange BaseItem medicineItem = createTestItem(""); Game.Instance.PlayerInstance.Health = 50; MedicineCategory medicineCategory = (MedicineCategory)medicineItem.GetItemCategoryByClass(typeof(MedicineCategory)); medicineCategory.Heal(); Assert.AreEqual(Game.Instance.PlayerInstance.Health, 55); Game.Instance.PlayerInstance.Health = 96; medicineCategory.Heal(); Assert.AreEqual(Game.Instance.PlayerInstance.Health, 100); }
public async Task <ActionResult> Add(MedicineCategoryModel model) { try { if (ModelState.IsValid) { MedicineCategory medCat = new MedicineCategory(); medCat.Name = model.Name; await _context.MedicineCategories.AddAsync(medCat); await _context.SaveChangesAsync(); } else { TempData["message"] = ModelState.ErrorGathering(); } return(RedirectToAction(nameof(Index))); } catch (Exception ex) { TempData["message"] = ex.Message; return(RedirectToAction(nameof(Index))); } }
protected void Seed(PharmAssistant.Models.PharmAssistantContext context) { // This method will be called after migrating to the latest version. // You can use the DbSet<T>.AddOrUpdate() helper extension method // to avoid creating duplicate seed data. AppUserManager userManager = new AppUserManager(new UserStore <AppUser>(context)); AppRoleManager roleManager = new AppRoleManager(new RoleStore <AppRole>(context)); string roleName = "Administrator"; string userName = "******"; string password = "******"; string email = "*****@*****.**"; if (!roleManager.RoleExists(roleName)) { roleManager.Create(new AppRole(roleName)); } AppUser user = userManager.FindByName(userName); if (user == null) { userManager.Create(new AppUser { UserName = userName, Email = email }, password); user = userManager.FindByName(userName); } if (!userManager.IsInRole(user.Id, roleName)) { userManager.AddToRole(user.Id, roleName); } foreach (AppUser dbuser in userManager.Users) { dbuser.City = "Baroda"; } context.Shelves.AddRange(new List <Shelf> { new Shelf { ShelfNumber = 1, ShelfName = "One" }, new Shelf { ShelfNumber = 2, ShelfName = "Two" }, new Shelf { ShelfNumber = 3, ShelfName = "Three" } }); context.SaveChanges(); context.Manufacturers.AddRange(new List <Manufacturer> { new Manufacturer { ManufacturerName = "Cipla", Address = "Baroda", ContactNo = 8857484748, EmailId = "*****@*****.**" }, new Manufacturer { ManufacturerName = "Torrent", Address = "Ahmedabad", ContactNo = 8859483948, EmailId = "*****@*****.**" }, new Manufacturer { ManufacturerName = "Sun Pharma", Address = "Baroda", ContactNo = 9098493849, EmailId = "*****@*****.**" }, }); context.SaveChanges(); var Supplier1 = new Supplier { SupplierName = "Supplier1", Address = "Baroda", ContactNo = 4738372837, EmailId = "*****@*****.**" }; var Supplier2 = new Supplier { SupplierName = "Supplier2", Address = "Baroda", ContactNo = 7758438373, EmailId = "*****@*****.**" }; var Supplier3 = new Supplier { SupplierName = "Supplier3", Address = "Ahmedabad", ContactNo = 9012837165, EmailId = "*****@*****.**" }; //context.Suppliers.AddRange(new List<Supplier> { Supplier1, Supplier2, Supplier3 }); //context.SaveChanges(); var Category1 = new MedicineCategory { MedicineCategoryName = "Tablet" }; var Category2 = new MedicineCategory { MedicineCategoryName = "Injectable" }; var Category3 = new MedicineCategory { MedicineCategoryName = "Syrup" }; Category1.Suppliers.Add(Supplier1); Category1.Suppliers.Add(Supplier3); Category2.Suppliers.Add(Supplier2); Category2.Suppliers.Add(Supplier3); Category3.Suppliers.Add(Supplier1); Category3.Suppliers.Add(Supplier2); context.MedicineCategories.AddRange(new List <MedicineCategory> { Category1, Category2, Category3 }); context.SaveChanges(); var Medicine1 = new Medicine { MedicineName = "Brufen", CostPrice = 12.50f, SellingPrice = 14.50f, Description = "Pain Killer", ShelfId = 1, CategoryId = 1, ManufacturerId = 1, StockCapacity = 200, ReorderLevel = 70, BufferLevel = 30 }; var Medicine2 = new Medicine { MedicineName = "Crocin", CostPrice = 14.50f, SellingPrice = 16.75f, Description = "Fever Relief", ShelfId = 1, CategoryId = 1, ManufacturerId = 3, StockCapacity = 250, ReorderLevel = 90, BufferLevel = 40 }; var Medicine3 = new Medicine { MedicineName = "Glycodin", CostPrice = 36.70f, SellingPrice = 38.50f, Description = "Cough Syrup", ShelfId = 3, CategoryId = 3, ManufacturerId = 2, StockCapacity = 175, ReorderLevel = 55, BufferLevel = 30 }; var Medicine4 = new Medicine { MedicineName = "Benadryl", CostPrice = 40.36f, SellingPrice = 43.50f, Description = "Cough Syrup", ShelfId = 3, CategoryId = 3, ManufacturerId = 3, StockCapacity = 200, ReorderLevel = 70, BufferLevel = 30 }; var Medicine5 = new Medicine { MedicineName = "Insulin Aspart", CostPrice = 32.50f, SellingPrice = 35.50f, Description = "Insulin", ShelfId = 2, CategoryId = 2, ManufacturerId = 1, StockCapacity = 220, ReorderLevel = 80, BufferLevel = 40 }; var Medicine6 = new Medicine { MedicineName = "Streptokinase", CostPrice = 120.40f, SellingPrice = 125.50f, Description = "Blood Thinner", ShelfId = 2, CategoryId = 2, ManufacturerId = 2, StockCapacity = 290, ReorderLevel = 100, BufferLevel = 60 }; Medicine1.Suppliers.Add(Supplier1); Medicine1.Suppliers.Add(Supplier3); Medicine2.Suppliers.Add(Supplier1); Medicine2.Suppliers.Add(Supplier2); Medicine3.Suppliers.Add(Supplier2); Medicine3.Suppliers.Add(Supplier3); Medicine4.Suppliers.Add(Supplier1); Medicine4.Suppliers.Add(Supplier2); Medicine5.Suppliers.Add(Supplier2); Medicine5.Suppliers.Add(Supplier3); Medicine6.Suppliers.Add(Supplier1); Medicine6.Suppliers.Add(Supplier3); context.Medicines.AddRange(new List <Medicine> { Medicine1, Medicine2, Medicine3, Medicine4, Medicine5, Medicine6 }); context.SaveChanges(); Customer customer1 = new Customer { CustomerName = "First Customer", Address = "Anand", ContactNumber = 8857483748, EmailId = "*****@*****.**" }; Customer customer2 = new Customer { CustomerName = "Second Customer", Address = "Ahmedabad", ContactNumber = 9847382938, EmailId = "*****@*****.**" }; Customer customer3 = new Customer { CustomerName = "Third Customer", Address = "Baroda", ContactNumber = 9944374837, EmailId = "*****@*****.**" }; context.Customers.AddRange(new List <Customer> { customer1, customer2, customer3 }); context.SaveChanges(); MembershipType membershipType1 = new MembershipType { MembershipTypeName = "Silver", MembershipTypeDesc = "Silver Membership", UpperBillLimit = 1500, BonusPoints = 150 }; MembershipType membershipType2 = new MembershipType { MembershipTypeName = "Gold", MembershipTypeDesc = "Gold Membership", UpperBillLimit = 2500, BonusPoints = 250 }; MembershipType membershipType3 = new MembershipType { MembershipTypeName = "Platinum", MembershipTypeDesc = "Platinum Membership", UpperBillLimit = 3500, BonusPoints = 350 }; context.MembershipTypes.AddRange(new List <MembershipType> { membershipType1, membershipType2, membershipType3 }); context.SaveChanges(); }
private BaseItem createTestItem() { PlayerInventory mockPlayerInventory = new PlayerInventory("player", 20); PlayerController controller = new GameObject().AddComponent <PlayerController>(); Game.Instance.PlayerInstance = new Player(mockPlayerInventory); Game.Instance.PlayerInstance.Controller = controller; BaseItem item = new BaseItem("Sample Item"); item.FlavorText = "This is a test item"; item.InventorySprite = "item.png"; item.WorldModel = "itemWorld.png"; item.Types = new List <string>(); item.Types.Add(ItemTypes.BaseSolid); item.Types.Add(ItemTypes.Rod); SolidCategory solid = new SolidCategory(); solid.Durability = 0.1f; solid.Elasticity = 0.2f; solid.Flexibility = 0.3f; solid.Sharpness = 0.4f; solid.Stickiness = 0.5f; solid.Thickness = 0.6f; PlantCategory plant = new PlantCategory(); plant.PneumoniaEffect = 0.1f; plant.StomachEffect = 0.2f; plant.Toughness = 0.3f; plant.WaterContent = 0.4f; FleshCategory flesh = new FleshCategory(); flesh.HealthEffect = 0.1f; flesh.HungerGain = 0.2f; ContainerCategory container = new ContainerCategory(); container.Size = 1; MedicineCategory medicine = new MedicineCategory(); medicine.HealthGain = 5f; medicine.Sickness = "all"; ClothCategory cloth = new ClothCategory(); cloth.FabricThickness = 0.5f; cloth.Impermiability = 1f; cloth.ThreadDensity = 0.3f; cloth.OnPlayer = 0f; FuelCategory fuel = new FuelCategory(); fuel.BurnTime = 5f; FireBaseCategory fire = new FireBaseCategory(); fire.BurnRateMultiplier = 1f; fire.FuelRemaining = 10f; fire.StartingFuel = 10f; ShelterCategory shelter = new ShelterCategory(); shelter.WarmthRate = 2; RaftCategory raft = new RaftCategory(); raft.Speed = 1f; raft.InventorySize = 5; WarmthIdolCategory warmthIdol = new WarmthIdolCategory(); warmthIdol.Equiped = 0f; warmthIdol.WarmthBenefit = 1; LightCategory light = new LightCategory(); light.Brightness = 2f; light.BurnRate = 0.75f; light.CurrentFuelLevel = 3f; light.MaxFuel = 5f; EquipableCategory equipable = new EquipableCategory(); equipable.Equiped = 0f; item.AddItemCategory(solid); item.AddItemCategory(plant); item.AddItemCategory(flesh); item.AddItemCategory(container); item.AddItemCategory(medicine); item.AddItemCategory(cloth); item.AddItemCategory(fuel); item.AddItemCategory(fire); item.AddItemCategory(shelter); item.AddItemCategory(raft); item.AddItemCategory(warmthIdol); item.AddItemCategory(light); item.AddItemCategory(equipable); return(item); }
// populate dropdown list for category of medicine private void SetMedicineCategoryData() { var objMedicineCategory = new MedicineCategory(); ddl_category.DataSource = objMedicineCategory.SelectAll(); ddl_category.DataTextField = "CategoryName"; ddl_category.DataValueField = "Id"; ddl_category.DataBind(); }