Exemple #1
0
 public void AddParticipantToReceipt(Receipt receipt, Participant participant)
 {
     if (!receipt.Participants.Exists(p => p.Name == participant.Name))
     {
         receipt.Participants.Add(participant);
         _collection.Save(receipt);
     }
 }
Exemple #2
0
 public static ReceiptViewModel ModelToViewModel(Receipt receipt, IEnumerable<Participant> list)
 {
     return new ReceiptViewModel
     {
         Date = receipt.Date,
         Description = receipt.Description,
         Id = receipt.Id.ToString(),
         Price = receipt.Price,
         Payer = new ParticipantViewModel (),
         Participants = list.Select(a => new ParticipantViewModel { Id = a.Id.ToString(), Name = a.Name }).ToList()
     };
 }
Exemple #3
0
 public ActionResult AddReceipt(Receipt receipt)
 {
     if(ModelState.IsValid && ReceiptValidator.Validate(receipt))
     {
         _receiptService.AddReceipt(receipt);
         return RedirectToAction("Index");
     }
     else
     {
         TempData["Errormessage"] = "Noen felter var ikke gyldige";
         return RedirectToAction("AddReceipt");
     }
 }
Exemple #4
0
 public void AddReceipt(Receipt receipt)
 {
     _collection.Insert(receipt);
 }
Exemple #5
0
 public static bool Validate(Receipt receipt)
 {
     return receipt.Participants != null && receipt.Payer != null;
 }
Exemple #6
0
        public void CreateTestData()
        {
            List<Receipt> testReceipts1; //betalt av Arnulf
            List<Receipt> testReceipts2; //Arnulf har deltatt på
            List<Participant> testParticipants1;
            List<Participant> testParticipants2;
            List<Participant> testParticipants3;

            var Stig = new Participant { Name = "Arnulf" };
            var Magnus = new Participant { Name = "Dingo" };
            var Jonas = new Participant { Name = "Hodor" };
            var Elisabeth = new Participant { Name = "Annie" };
            var Monika = new Participant { Name = "Abed" };
            var Oyvin = new Participant { Name = "Yussuf" };

            testParticipants1 = new List<Participant>();
            testParticipants2 = new List<Participant>();
            testParticipants3 = new List<Participant>();
            testReceipts1 = new List<Receipt>();
            testReceipts2 = new List<Receipt>();

            testParticipants1.Add(Stig);
            testParticipants1.Add(Magnus);
            testParticipants1.Add(Jonas);

            testParticipants2.Add(Elisabeth);
            testParticipants2.Add(Jonas);
            testParticipants2.Add(Stig);

            testParticipants3.Add(Oyvin);
            testParticipants3.Add(Monika);

            var middag1 = new Receipt
            {
                Date = DateTime.Now,
                Month = DateTime.Now.Month,
                Payer = Stig,
                Description = "test1",
                Price = 45.0,
                Participants = testParticipants1
            };
            var middag2 = new Receipt
            {
                Date = DateTime.Now,
                Month = DateTime.Now.Month,
                Payer = Stig,
                Description = "test2",
                Price = 85.0,
                Participants = testParticipants3
            };
            var middag3 = new Receipt
            {
                Date = DateTime.Now,
                Month = 14,
                Payer = Monika,
                Description = "test3",
                Price = 60.0,
                Participants = testParticipants1
            };
            var middag4 = new Receipt
            {
                Date = DateTime.Now,
                Month = DateTime.Now.Month,
                Payer = Elisabeth,
                Description = "test4",
                Price = 90.0,
                Participants = testParticipants1
            };
            var middag5 = new Receipt
            {
                Date = DateTime.Now,
                Month = 14,
                Payer = Stig,
                Description = "test5",
                Price = 65.0,
                Participants = testParticipants3
            };

            testReceipts1.Add(middag1);
            testReceipts1.Add(middag2);
            testReceipts1.Add(middag5);

            testReceipts2.Add(middag1);
            testReceipts2.Add(middag3);
            testReceipts2.Add(middag4);

            foreach (Participant participant in testParticipants1)
            {
                _participantservice.AddParticipant(participant);
            }
            foreach (Participant participant in testParticipants2)
            {
                _participantservice.AddParticipant(participant);
            }
            foreach (Participant participant in testParticipants3)
            {
                _participantservice.AddParticipant(participant);
            }
            foreach (Receipt receipt in testReceipts1)
            {
                _receiptService.AddReceipt(receipt);
            }
            foreach (Receipt receipt in testReceipts2)
            {
                _receiptService.AddReceipt(receipt);
            }
        }
Exemple #7
0
 public PartialViewResult ParticipantsListForReceipt(Receipt receipt)
 {
     return PartialView("_ParticipantsListDisplay", receipt.Participants);
 }