示例#1
0
        public void EditExpense()
        {
            var person1 = new Person { ChangeSetN = 1, DisplayName = "Bobby", PersonId = 1, RowId = Guid.NewGuid() };
            var person2 = new Person { ChangeSetN = 1, DisplayName = "Sophie", PersonId = 2, RowId = Guid.NewGuid() };
            var person3 = new Person { ChangeSetN = 1, DisplayName = "Glenn", PersonId = 3, RowId = Guid.NewGuid() };

            var trip = new Trip
                {
                    ChangeSetN = 1,
                    DisplayName = "Paris 2011",
                    RowId = Guid.NewGuid(),
                    TripId = 1
                };

            var expense = new Expense
                {
                    Amount = 100,
                    ChangeSetN = 1,
                    DisplayName = "Beers",
                    ExpenseId = 1,
                    Sender = person1,
                    Receivers = new List<Person> { person1, person2 },
                    RecordDate = new DateTime(2011, 01, 02, 15, 30, 00),
                    RowId = Guid.NewGuid(),
                    Trip = trip
                };

            var oldExpenseRowId = expense.RowId;

            var viewModel = new ExpenseViewModel { Model = expense };

            viewModel.LoadFromModel();

            // Switch the payer from person1 to person3 (and also receiver)
            viewModel.Sender = person3;
            viewModel.Receivers.Remove(person1);
            viewModel.Receivers.Add(person3);

            viewModel.SaveToModel();

            Assert.AreEqual(100, expense.Amount);
            Assert.AreEqual(1, expense.ExpenseId);
            Assert.AreEqual(expense.Sender, person3);
            Assert.AreEqual(2, expense.Receivers.Count);
            Assert.IsTrue(expense.Receivers.Contains(person2));
            Assert.IsTrue(expense.Receivers.Contains(person3));
            Assert.AreEqual(new DateTime(2011, 01, 02, 15, 30, 00), expense.RecordDate);
            Assert.AreNotEqual(oldExpenseRowId, expense.RowId);
            Assert.AreEqual(expense.Trip, trip);
        }
示例#2
0
        public ActionResult Create(int collectionId, Expense expense, FormCollection formCollection)
        {
            //throw new NotImplementedException();

            /*ar people = db.People.ToList();
            ViewBag.People = people;

            var selectedUsedBy = formCollection["usedBy"].Split(',').Select(x => int.Parse(x)).ToList();
            ViewBag.UsedByCheckList = people.ToDictionary(p => p, p => selectedUsedBy.Contains(p.PersonId));

            if (ModelState.IsValid)
            {
                ((Dictionary<int, bool>)ViewBag.UsedByCheckList).Where(x => x.Value)
                        .Select(x => db.People.Find(x.Key)).ToList().ForEach(x => expense.Receivers.Add(x));

                db.Expenses.Add(expense);
                db.SaveChanges();

                return RedirectToAction("Index", new { expense.CollectionId });
            }*/

            expense.Receivers = new List<Person>(
                ParseCheckBoxes(
                    formCollection["PossibleUsers.kvp.Item1.PersonId"],
                    formCollection["PossibleUsers.kvp.Item2"]).Where(t => t.Item2).Select(t => db.People.Find(t.Item1)));
            expense.TripId = collectionId;

            if (ModelState.IsValid)
            {
                db.Expenses.Add(expense);
                db.SaveChanges();

                return RedirectToAction("Index", new { CollectionId = expense.TripId });
            }

            var viewModel = new ExpenseViewModel { Expense = expense };

            this.CompleteViewModel(viewModel);

            return View(viewModel);
        }
示例#3
0
        private void ApplicationBarIconButton_Click(object sender, EventArgs e)
        {
            var expense = new Expense
                {
                    RowId = Guid.NewGuid(),
                    DisplayName = "New expense",
                    RecordDate = DateTime.Now,
                    Sender = null,
                    Receivers = new List<Person>(),
                    Trip = (Trip)Repository.Instance[this.ViewModel.Model.Key],
                    Amount = 0
                };

            var key = Repository.Instance.Add(expense);

            NavigationService.Navigate(new Uri("/Views/ExpenseView.xaml?id=" + key, UriKind.Relative));
        }
示例#4
0
        public ActionResult Edit(Expense expense)
        {
            if (ModelState.IsValid)
            {
                db.Entry(expense).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index", new { collectionId = expense.TripId });
            }

            return View(expense);
        }