public void TestUpdateVisit()
        {
            this.GetMemoContext().Database.EnsureDeleted();

            VisitBO visit = new VisitBO()
            {
                Id                   = 1,
                Title                = "Besøg",
                Description          = "Godt besøg",
                DateTimeOfVisitStart = DateTime.Today,
                IsDone               = true,
                CustomerId           = 2,
                EmployeeId           = 1
            };

            visit = this.GetService().Create(visit);
            Assert.AreEqual("Besøg", this.GetService().Get(visit.Id).Title);
            visit.Title       = "Visit";
            visit.Description = "Nice visit";
            this.GetService().Update(visit);
            visit.IsDone = false;
            visit.DateTimeOfVisitStart = DateTime.Now;
            this.GetService().Update(visit);
            Assert.AreEqual("Visit", this.GetService().Get(1).Title);
            Assert.AreEqual("Nice visit", this.GetService().Get(1).Description);
            Assert.AreEqual(false, this.GetService().Get(1).IsDone);
        }
 public VisitBO Create(VisitBO visit)
 {
     using (var uow = this.facade.UnitOfWork)
     {
         this.newVisit = uow.VisitRepository.Create(this.visitConv.Convert(visit));
         uow.Complete();
         return(this.visitConv.Convert(this.newVisit));
     }
 }
 public IActionResult Post([FromBody] VisitBO visit)
 {
     //TODO You dont use modelstate
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     return(Ok(_facade.VisitService.Create(visit)));
 }
 public IActionResult Put(int id, [FromBody] VisitBO visit)
 {
     if (id != visit.Id)
     {
         return(StatusCode(405, "Path id does not match customer ID json object"));
     }
     try
     {
         return(Ok(_facade.VisitService.Update(visit)));
     }
     catch (InvalidOperationException e)
     {
         return(StatusCode(404, e.Message));
     }
 }
        public VisitBO Update(VisitBO visit)
        {
            using (var uow = this.facade.UnitOfWork)
            {
                // Gets visit from db with ID that matches
                var visitFromDb = uow.VisitRepository.Get(visit.Id);

                visitFromDb.Title                = visit.Title;
                visitFromDb.Description          = visit.Description;
                visitFromDb.IsDone               = visit.IsDone;
                visitFromDb.DateTimeOfVisitStart = visit.DateTimeOfVisitStart;
                visitFromDb.DateTimeOfVisitEnd   = visit.DateTimeOfVisitEnd;
                uow.Complete();
                return(this.visitConv.Convert(visitFromDb));
            }
        }
        public void TestCreateVisit()
        {
            this.GetMemoContext().Database.EnsureDeleted();
            VisitBO visit = new VisitBO()
            {
                Title                = "Besøg",
                Description          = "Godt besøg",
                DateTimeOfVisitStart = DateTime.Today,
                IsDone               = true,
                CustomerId           = 2,
                EmployeeId           = 1
            };

            this.GetService().Create(visit);
            Assert.IsNotNull(visit);
            Assert.AreEqual("Besøg", visit.Title);
            Assert.AreEqual("Godt besøg", visit.Description);
        }
 public Visit Convert(VisitBO visit)
 {
     if (visit == null)
     {
         return(null);
     }
     {
         return(new Visit()
         {
             Id = visit.Id,
             Title = visit.Title,
             Description = visit.Description,
             IsDone = visit.IsDone,
             DateTimeOfVisitStart = visit.DateTimeOfVisitStart,
             DateTimeOfVisitEnd = visit.DateTimeOfVisitEnd,
             CustomerId = visit.CustomerId,
             Customer = _custConv.Convert(visit.Customer),
             EmployeeId = visit.EmployeeId,
             Employee = _empConv.Convert(visit.Employee)
         });
     }
 }