public JsonResult DeleteActivity(int id) { try { JourListDMContainer dm = new JourListDMContainer(); // Grab the goal Activity a = dm.Activities.Single(z => z.Id == id); // Delete the object only if there are no references if (a.ActivityLogs.Count < 1) { dm.Activities.DeleteObject(a); } // Otherwise just deactivate so we don't break any historical records else { a.Active = false; } // Save the changes dm.SaveChanges(); return(Json(new { Result = "OK" })); } catch (Exception e) { return(Json(new { Result = "ERROR", Message = e.Message })); } }
public JsonResult NewTransaction(string InvId, string ActionId) { JourListDMContainer dm = new JourListDMContainer(); long id; if (!long.TryParse(InvId, out id)) { return(JsonError("Invalid item jourId")); } int aid; if (!int.TryParse(ActionId, out aid)) { return(JsonError("Invalid action jourId")); } var member = dm.Members.SingleOrDefault(z => z.Name == User.Identity.Name); if (member == null) { return(JsonError("You don't exist")); } return(JsonOk(new TransactionModel(aid, User.Identity.Name, id))); }
//// //// POST: /DataManagement/GetActivityOptions //[HttpPost] //public JsonResult GetActivityOptions() //{ // try // { // JourListDMContainer dm = new JourListDMContainer(); // var list = dm.Activities.Select(z => new { DisplayText = z.Description, Value = z.Id }); // return Json(new { Result = "OK", Options = list }); // } // catch (Exception e) // { // return Json(new { Result = "ERROR", Message = e.Message }); // } //} #endregion #region Unit // POST: /DataManagement/UnitList public JsonResult UnitList() { try { JourListDMContainer dm = new JourListDMContainer(); List <UnitModel> list = new List <UnitModel>(); foreach (var a in dm.Units.Where(z => z.Active == true)) { UnitModel item = new UnitModel(); item.Id = a.Id; item.Description = a.Description; item.ConversionFactor = a.ConversionFactor; item.UnitTypeId = a.UnitType.Id; item.Abbreviation = a.Abbreviation; item.Active = a.Active; list.Add(item); } return(Json(new { Result = "OK", Records = list })); } catch (Exception e) { return(Json(new { Result = "ERROR", Message = e.Message })); } }
public JsonResult Transact(TransactionModel model) { JourListDMContainer dm = new JourListDMContainer(); Member member = dm.Members.SingleOrDefault(z => z.Name == User.Identity.Name); if (!User.Identity.IsAuthenticated || member == null) { return(JsonError("You need to log in to use the shopping cart.")); } try { var log = UpdateStock(model); model.TransId = log.Id; model.TimeStamp = log.TransactionDate; } catch (Exception e) { return(JsonError(e.Message)); throw; } TransactionModel nmodel = new TransactionModel(model.ActionId, member.Name); return(JsonOk(new { NextItem = nmodel, Transaction = model })); }
public JsonResult ActivityList() { try { JourListDMContainer dm = new JourListDMContainer(); List <ActivityModel> list = new List <ActivityModel>(); foreach (var a in dm.Activities)//.Where(z => z.Active == true)) { ActivityModel atemp = new ActivityModel(); atemp.Id = a.Id; atemp.Description = a.Description; atemp.Points = a.Points; atemp.Active = a.Active; atemp.UnitId = a.Unit.Id; atemp.Quantity = a.Quantity; list.Add(atemp); } return(Json(new { Result = "OK", Records = list })); } catch (Exception e) { return(Json(new { Result = "ERROR", Message = e.Message })); } }
public JsonResult UpdateActivity(ActivityModel model) { try { if (!ModelState.IsValid) { return(Json(new { Result = "ERROR", Message = "Form is not valid! " + "Please correct it and try again." })); } JourListDMContainer dm = new JourListDMContainer(); Activity activity = dm.Activities.Single(z => z.Id == model.Id); activity.Description = model.Description; activity.Points = model.Points; activity.Unit = dm.Units.Single(z => z.Id == model.UnitId); activity.Quantity = model.Quantity; dm.SaveChanges(); return(Json(new { Result = "OK" })); } catch (Exception e) { return(Json(new { Result = "ERROR", Message = e.Message })); } }
public JsonResult Save(JournalModel model) { if (User.Identity.IsAuthenticated == false) { return(JsonError("You are not authenticated")); } JourListDMContainer dm = new JourListDMContainer(); var member = dm.Members.SingleOrDefault(z => z.Name == User.Identity.Name); if (member == null) { return(JsonError("You are not registered in the system")); } var journal = member.Journals.SingleOrDefault(z => z.Id == model.JourId); if (journal == null) { return(JsonError("You can't save a journal that doesn't exist. Or at least, technically you could by creating a new one... but that should have already been done. If it hasn't already been done then you're working outside the system.")); } journal.Weight = model.Weight; journal.HeartRate = model.HeartRate; journal.Story = model.Story; journal.Encrypted = model.Encrypted; dm.SaveChanges(); model.JourId = journal.Id; return(JsonOk(model)); }
//// //// POST: /DataManagement/GetInventoryActionOptions //[HttpPost] //public JsonResult GetInventoryActionOptions() //{ // try // { // JourListDMContainer dm = new JourListDMContainer(); // var list = dm.InventoryActions.Select(z => new { DisplayText = z.Description, Value = z.Id }); // return Json(new { Result = "OK", Options = list }); // } // catch (Exception e) // { // return Json(new { Result = "ERROR", Message = e.Message }); // } //} #endregion #region Items // POST: /DataManagement/ItemList public JsonResult ItemList(FormCollection collection) { try { JourListDMContainer dm = new JourListDMContainer(); List <ItemModel> list = new List <ItemModel>(); foreach (var a in dm.Items.OfType <StandardItem>().Where(z => z.Active == true)) { ItemModel item = new ItemModel(); item.Id = a.Id; item.Description = a.Description; //item.Hyperlink = a.Hyperlink; //item.Barcode = a.Barcode; item.CategoryId = a.ItemCategory.Id; item.UnitTypeId = a.UnitType.Id; item.Active = a.Active; list.Add(item); } return(Json(new { Result = "OK", Records = list })); } catch (Exception e) { return(Json(new { Result = "ERROR", Message = e.Message })); } }
public JsonResult DeleteActivityLog(long LogId) { JourListDMContainer dm = new JourListDMContainer(); if (User.Identity.IsAuthenticated != true) { return(JsonError("Please log in")); } var member = dm.Members.SingleOrDefault(z => z.Name == User.Identity.Name); if (member == null) { return(JsonError("You do not exist")); } var log = dm.ActivityLogs.SingleOrDefault(z => z.Id == LogId); if (log == null) { return(JsonError("That log does not exist")); } if (log.Journal.Member != member) { return(JsonError("This log does not belong to you")); } dm.ActivityLogs.DeleteObject(log); dm.SaveChanges(); return(JsonOk("Deleted")); }
public JsonResult DeleteItem(int id) { if (!User.Identity.IsAuthenticated) { return(Json(new { Result = "ERROR", Message = "You need to log in to delete an item." })); } if (!User.IsInRole("Officer")) { return(Json(new { Result = "ERROR", Message = "You do not have the authority to delete an item." })); } try { JourListDMContainer dm = new JourListDMContainer(); // Grab the item Item item = dm.Items.OfType <StandardItem>().Single(z => z.Id == id); if (item == null) { return(Json(new { Result = "ERROR", Message = "The item for deletion does not exist!" })); } // Delete the object only if there are no references if (item.Inventories.Count < 1) { dm.Items.DeleteObject(item); } // Otherwise just deactivate so we don't break any historical records else { item.Active = false; } // Save the changes dm.SaveChanges(); return(Json(new { Result = "OK" })); } catch (Exception e) { return(Json(new { Result = "ERROR", Message = e.Message })); } }
// Create repository, find user private void setup(string member) { dm = new JourListDMContainer(); __member = dm.Members.SingleOrDefault(z => z.Name == member); if (__member == null) { throw new Exception("You are not registered in the system"); } }
public JsonResult SearchInventory(string term) { JourListDMContainer dm = new JourListDMContainer(); var items = from c in dm.Members.Single(z => z.Name == User.Identity.Name).Inventories where c.Item.Description.ToUpper().Contains(term.ToUpper()) select new { value = c.Id, label = c.Item.Description }; return(this.Json(items)); }
public JsonResult UpdateUnit(UnitModel model) { try { if (!ModelState.IsValid) { return(Json(new { Result = "ERROR", Message = "Form is not valid! " + "Please correct it and try again." })); } if (!User.IsInRole("Officer")) { return(Json(new { Result = "ERROR", Message = "You do not have the authority to update this unit." })); } JourListDMContainer dm = new JourListDMContainer(); Unit unit = dm.Units.Single(z => z.Id == model.Id); unit.Description = model.Description; unit.Abbreviation = model.Abbreviation; unit.ConversionFactor = model.ConversionFactor; unit.UnitType = dm.UnitTypes.Single(z => z.Id == model.UnitTypeId); if (model.ConversionFactor == 1 && unit.UnitType.DefaultUnit != null && unit.UnitType.DefaultUnit.Active) { return(Json(new { Result = "ERROR", Message = "An active default unit with conversion factor of 1 already exists." })); } else if (model.ConversionFactor == 1) { unit.UnitType.DefaultUnit = unit; } unit.Active = model.Active; dm.SaveChanges(); return(Json(new { Result = "OK" })); } catch (Exception e) { return(Json(new { Result = "ERROR", Message = e.Message })); } }
public ActivityLogModel(long ActId) { JourListDMContainer dm = new JourListDMContainer(); var act = dm.Activities.Single(z => z.Id == ActId); set(null, act); // TODO: Complete member initialization this.Quantity = 0; this.unitid = act.Unit.Id; }
public JsonResult CreateItem(ItemModel model) { if (!ModelState.IsValid) { return(Json(new { Result = "ERROR", Message = "Form is not valid! " + "Please correct it and try again." })); } if (!User.Identity.IsAuthenticated) { return(Json(new { Result = "ERROR", Message = "You need to log in to add an item." })); } if (!User.IsInRole("Officer")) { return(Json(new { Result = "ERROR", Message = "You do not have the authority to create a new inventory item." })); } try { JourListDMContainer dm = new JourListDMContainer(); StandardItem item = new StandardItem(); item.Description = model.Description; //if (model.Hyperlink != null) item.Hyperlink = model.Hyperlink; //if (model.Barcode != null) item.Barcode = model.Barcode; item.ItemCategory = dm.ItemCategories.Single(z => z.Id == model.CategoryId); item.UnitType = dm.UnitTypes.Single(z => z.Id == model.UnitTypeId); dm.AddToItems(item); dm.SaveChanges(); model.Id = item.Id; return(Json(new { Result = "OK", Record = model })); } catch (Exception e) { return(Json(new { Result = "ERROR", Message = e.Message })); } }
public ActivityLogModel(long LogId, string memberName) { JourListDMContainer dm = new JourListDMContainer(); var mem = dm.Members.SingleOrDefault(z => z.Name == memberName); var log = dm.ActivityLogs.Single(z => z.Id == LogId); if (log.Journal.Member.Name != memberName) { throw new Exception("Log does not belong to user"); } set(log, log.Activity); }
public JsonResult UnitTypes() { try { JourListDMContainer dm = new JourListDMContainer(); var list = dm.UnitTypes.Select(z => new { DisplayText = z.Description, Value = z.Id }); return(Json(new { Result = "OK", Options = list })); } catch (Exception e) { return(Json(new { Result = "ERROR", Message = e.Message })); } }
public JsonResult StandardItems() { try { JourListDMContainer dm = new JourListDMContainer(); var list = dm.Items.OfType <PersonalItem>().Select(z => new { DisplayText = z.Description, Value = z.Id }) .OrderByDescending(z => z.DisplayText); return(Json(new { Result = "OK", Options = list })); } catch (Exception e) { return(Json(new { Result = "ERROR", Message = e.Message })); } }
public JsonResult UpdateActivityLog(ActivityLogModel model) { JourListDMContainer dm = new JourListDMContainer(); if (User.Identity.IsAuthenticated != true) { return(JsonError("Please log in")); } var member = dm.Members.SingleOrDefault(z => z.Name == User.Identity.Name); if (member == null) { return(JsonError("You do not exist")); } var log = dm.ActivityLogs.SingleOrDefault(z => z.Id == model.LogId); if (log == null) { return(JsonError("That log does not exist")); } if (log.Journal.Member != member) { return(JsonError("This log does not belong to you")); } var unit = dm.Units.SingleOrDefault(z => z.Id == model.UnitId); if (unit == null) { return(JsonError("A unit by that ID does not exist")); } if (unit.UnitType != log.Activity.Unit.UnitType) { return(JsonError("Your unit is not the same type as the activity's")); } log.Unit = unit; log.Hyperlink = model.Hyperlink; log.Notes = model.Notes; log.Quantity = model.Quantity; dm.SaveChanges(); return(JsonOk(model)); }
public ActionResult ShoppingList() { if (!User.Identity.IsAuthenticated) { return(RedirectToAction("LogOn", "Account")); } JourListDMContainer dm = new JourListDMContainer(); var member = dm.Members.SingleOrDefault(z => z.Name == User.Identity.Name); if (member == null) { return(RedirectToAction("LogOn", "Account")); } return(View(GenerateShoppingList(member))); }
// // POST: /Inventory/GetStandardItems public JsonResult GetStandardItems(FormCollection collection) { if (!User.Identity.IsAuthenticated) { return(JsonError("You need to log in to add personal items.")); } try { JourListDMContainer dm = new JourListDMContainer(); // if convsconversion fails, the out value is false bool _showinactive; string showinactive = collection["ShowInactive"]; bool.TryParse(showinactive, out _showinactive); //// Get all of the member's standard items //var sitems = dm.Items.OfType<StandardItem>(); //foreach (var s in sitems) //{ // var witems = s.Inventories.Where(y => y.Member.Name == User.Identity.Name && y.Active == true); //} var pitems = (IEnumerable <Item>)dm.Members.First(z => z.Name == User.Identity.Name).PersonalItems .Where(z => z.Inventories.FirstOrDefault(y => y.Member.Name == User.Identity.Name && y.Active == true) == null); var sitems = (IEnumerable <Item>)dm.Items.OfType <StandardItem>() // Where the item is not already in the member's inventory .Where(z => z.Inventories.FirstOrDefault(y => y.Member.Name == User.Identity.Name // And make sure to grab inactivated inventories && y.Active == true) == null); var items = pitems.Union(sitems); if (!_showinactive) { items = items.Where(z => true == z.Active); } return(CreateItemModelList(items)); } catch (Exception e) { return(Json(new { Result = "ERROR", Message = e.Message })); } }
public JsonResult DeleteUnit(int id) { if (!User.IsInRole("Officer")) { return(Json(new { Result = "ERROR", Message = "You do not have the authority to delete this unit." })); } try { JourListDMContainer dm = new JourListDMContainer(); // Grab the goal Unit u = dm.Units.Single(z => z.Id == id); if (u.UnitType.DefaultUnit == u) { u.UnitType.DefaultUnit = null; } // Delete the object only if there are no references if (u.ActivityLogs.Count < 1 && u.UnitType.DefaultUnit != u && u.Inventories.Count < 1) { dm.Units.DeleteObject(u); } // Otherwise just deactivate so we don't break any historical records else { u.Active = false; } // Save the changes dm.SaveChanges(); return(Json(new { Result = "OK" })); } catch (Exception e) { return(Json(new { Result = "ERROR", Message = e.Message })); } }
private void UpdateShoppingList(Inventory inventory) { JourListDMContainer dm = new JourListDMContainer(); var inv = dm.Inventories.Single(z => z.Id == inventory.Id); bool needmore, needlist; // deal with shopping list if necessary needmore = inv.OnHand < inv.RestockThreshold; needlist = inv.ShoppingList == null; if (needmore) { if (needlist) { // Createlist ShoppingList list = new ShoppingList(); do { list.Id = Guid.NewGuid(); }while (dm.ShoppingLists.Count(z => z.Id == list.Id) > 0); dm.AddToShoppingLists(list); inv.ShoppingList = list; } var log = inv.InventoryLogs.Where(z => z.UnitId == inv.Unit.Id); if (log.Count() > 0) { double sze = (from a in log group a by a.Size into s orderby s.Count() descending select s).First().First().Size; inv.ShoppingList.SizeNeeded = sze; inv.ShoppingList.QuantityNeeded = Math.Round((inv.RequiredQuantity - inv.OnHand) / sze, MidpointRounding.AwayFromZero); } else { inv.ShoppingList.SizeNeeded = (inv.RequiredQuantity - inv.OnHand); inv.ShoppingList.QuantityNeeded = 1; } } else if (!needlist) { // Remove the item from the shoppinglist dm.ShoppingLists.DeleteObject(dm.Inventories.First(z => z.ShoppingList.Id == inv.ShoppingList.Id).ShoppingList); } dm.SaveChanges(); }
public JsonResult DeleteInventoryAction(int id) { if (!User.IsInRole("Officer")) { return(Json(new { Result = "ERROR", Message = "You do not have the authority delete this inventory action." })); } try { JourListDMContainer dm = new JourListDMContainer(); // Grab the item InventoryAction item = dm.InventoryActions.Single(z => z.Id == id); // Delete the object only if there are no references if (item.InventoryLogs.Count < 1) { dm.InventoryActions.DeleteObject(item); } // Otherwise just deactivate so we don't break any historical records else { return(Json(new { Result = "ERROR", Message = "Please eliminate references to delete." })); } // Save the changes dm.SaveChanges(); return(Json(new { Result = "OK" })); } catch (Exception e) { return(Json(new { Result = "ERROR", Message = e.Message })); } }
/// <summary> /// Add an inventory item given an item model if it doesn't exist /// Reactivates it if deactivated /// </summary> /// <param name="model"></param> /// <returns>The manipulated/created inventory entry</returns> private Inventory AddToInventory(ItemModel model) { JourListDMContainer dm = new JourListDMContainer(); var member = dm.Members.SingleOrDefault(z => z.Name == User.Identity.Name); if (member == null) { return(null); } // If inventory already exists but is inactive, reactivate // If it exists and is active, then just return the inventory item, do nothing Inventory inv; if ((inv = member.Inventories.FirstOrDefault(z => z.Item.Id == model.Id)) != null) { if (inv.Active == false) { inv.Active = true; } else { return(inv); } } // Add an inventory listing if it doesn't exist. else { inv = new Inventory(); inv.Item = dm.Items.Single(z => z.Id == model.Id); inv.RestockThreshold = model.RestockThreshold; inv.OnHand = model.OnHand; inv.RequiredQuantity = model.RequiredQuantity; inv.Unit = dm.Units.Single(z => z.Id == model.UnitId); inv.Member = member; dm.AddToInventories(inv); } dm.SaveChanges(); return(inv); }
// // POST: /Inventory/GetInventory public JsonResult GetInventory(FormCollection collection) { if (!User.Identity.IsAuthenticated) { return(Json(new { Result = "ERROR", Message = "You need to log in to add personal items." })); } try { JourListDMContainer dm = new JourListDMContainer(); List <Item> items = new List <Item>(); // if convsconversion fails, the out value is false bool _showinactive; string showinactive = collection["ShowInactive"]; bool.TryParse(showinactive, out _showinactive); // Get only the active items if we don't want to show the inactive ones foreach (var inv in dm.Members.Single(z => z.Name == User.Identity.Name).Inventories) { if (!_showinactive && !inv.Active) { continue; } else { items.Add(inv.Item); } } return(CreateItemModelList(items)); } catch (Exception e) { return(Json(new { Result = "ERROR", Message = e.Message })); } }
public JsonResult GetTodayTransactions(FormCollection collection) { List <TransactionModel> ltm = new List <TransactionModel>(); JourListDMContainer dm = new JourListDMContainer(); DateTime morn; if (collection["Day"] != null) { morn = DateTime.Parse(collection["Day"]); } else { morn = DateTime.Today.Date; } DateTime eve = morn.AddDays(1); var trans = dm.InventoryLogs.Where(z => z.Inventory.Member.Name == User.Identity.Name && z.TransactionDate <= eve && z.TransactionDate >= morn); foreach (var t in trans) { // var tt = new TransactionModel(t); //TransactionModel tm = new TransactionModel(); //tm.InvId = t.Inventory.Id; //tm.TransId = t.Id; //tm.Quantity = t.Quantity; //tm.Size = t.Size; //tm.UnitId = t.Unit.Id; //tm.ActionId = t.InventoryAction.Id; //tm.Cost = t.Cost; //tm.Description = t.Inventory.Item.Description; //tm.TimeStamp = t.TransactionDate; ltm.Add(new TransactionModel(t)); } // TODO: Implement return(JsonOk(ltm)); }
public JsonResult GetActivityLogs(string Day) { if (User.Identity.IsAuthenticated == false) { return(JsonError("You are not authenticated")); } DateTime date; if (Day == null) { date = DateTime.Today; } else { date = DateTime.Parse(Day); } var dm = new JourListDMContainer(); var list = new List <ActivityLogModel>(); var member = dm.Members.SingleOrDefault(z => z.Name == User.Identity.Name); if (member == null) { return(JsonError("You don't exist")); } var journal = member.Journals.SingleOrDefault(z => z.EntryDate == date); if (journal == null) { return(JsonOk("")); } foreach (var log in journal.ActivityLogs) { list.Add(new ActivityLogModel(log.Id, User.Identity.Name)); } return(JsonOk(list)); }
public JsonResult DeleteItemCategory(int id) { if (!User.IsInRole("Officer")) { return(Json(new { Result = "ERROR", Message = "You do not have the authority delete this item category." })); } try { JourListDMContainer dm = new JourListDMContainer(); // Grab the item ItemCategory cat = dm.ItemCategories.Single(z => z.Id == id); // Delete the object only if there are no references if (cat.Items.Count < 1) { dm.ItemCategories.DeleteObject(cat); } // Otherwise just deactivate so we don't break any historical records else { cat.Active = false; } // Save the changes dm.SaveChanges(); return(Json(new { Result = "OK" })); } catch (Exception e) { return(Json(new { Result = "ERROR", Message = e.Message })); } }
public JsonResult CreateReccurenceInterval(RecurrenceIntervalModel model) { if (!ModelState.IsValid) { return(Json(new { Result = "ERROR", Message = "Form is not valid! " + "Please correct it and try again." })); } if (!User.IsInRole("Officer")) { return(Json(new { Result = "ERROR", Message = "You do not have the authority to create a new interval." })); } try { JourListDMContainer dm = new JourListDMContainer(); RecurrenceInterval item = new RecurrenceInterval(); item.Description = model.Description; item.Minutes = model.Minutes; dm.AddToRecurrenceIntervals(item); dm.SaveChanges(); model.Id = item.Id; return(Json(new { Result = "OK", Record = model })); } catch (Exception e) { return(Json(new { Result = "ERROR", Message = e.Message })); } }