private static string Ins(BsonDocument doc) { try { BsonValue id; if (!doc.TryGetValue("_id", out id)) throw new Exception("fant ikke _id"); var exp = new ExpenseModel { IsCommon = doc.GetValue("IsCommon", true).ToBoolean(), IsPossibleDuplicate = doc.GetValue("IsPossibleDuplicate", false).ToBoolean(), Means = doc.GetValue("Means", string.Empty).ToString(), Owner = doc.GetValue("Owner", string.Empty).ToString(), Amount = doc.GetValue("Amount", 0).ToDouble(), Description = doc.GetValue("Description", string.Empty).ToString(), Date = doc.GetValue("Date").AsDateTime }; var nu = ModelCollection<ExpenseModel>.InsertItem(exp); return "insert " + nu.Id; } catch (Exception ex) { return ex.Message; } }
public ActionResult Edit(ExpenseModel expense) { if (!ModelState.IsValid) { return View(expense); } if (ExpenseDataManager.UpdateItem(expense)) return RedirectToAction("Index", "List"); return View(expense); }
public static bool UpdateItem(ExpenseModel expense) { try { ModelCollection<ExpenseModel>.UpdateItem(expense); return true; } catch { return false; } }
public static void InsertItem(ExpenseModel expense) { ModelCollection<ExpenseModel>.InsertItem(expense); }
public List<ExpenseModel> Parse(string identity) { if (FileStream==null) throw new NullReferenceException("ingen fil funnet"); var expenseList = new List<ExpenseModel>(); var streamReader = new StreamReader(FileStream, Encoding.Default); if (streamReader.BaseStream.Length == 0) return expenseList; if( HasHeaderRow) streamReader.ReadLine(); while( streamReader.Peek() >= 0 ) { var sb = streamReader.ReadLine(); var fields = Split(sb); if( fields.Count == 0) continue; DateTime date; if (!DateTime.TryParse(fields[DatePos],out date)) continue; string description = fields[DescPos]; double amount; if (!double.TryParse(fields[AmountPos], out amount)) amount = 0; // a.k.a. no expense if (amount == 0) continue; var em = new ExpenseModel { Date = date, Description = description, Owner = identity, Amount = amount, Means = SourceName, IsCommon = true }; expenseList.Add(em); } return expenseList; }
public ActionResult Insert(ExpenseModel expense) { if (!ModelState.IsValid) { return View(expense); } ExpenseDataManager.InsertItem(expense); return RedirectToAction("Index", "List"); }