Exemple #1
0
        public async Task <IHttpActionResult> Add(AddVisitBindingModel model)
        {
            try
            {
                VisitTerm visitTerm = await _unitOfWork.VisitTermRepository.AddVisitTermOrReturnIfExists(model.StartDate);

                Visit visit = Visit.Create(model.ServiceId, visitTerm.Id, User.Identity.GetUserId(), model.StartDate);
                visit = _mapper.Map(model, visit);

                await _unitOfWork.VisitRepository.Add(visit);

                await _unitOfWork.CompleteAsync();

                var addedVisit = await _unitOfWork.VisitRepository.FindWithCustomerAndServiceAsync(visit.Id);

                var result = _mapper.Map <VisitInfoBindingModel>(addedVisit);

                return(Ok(result));
            }
            catch (VisitCurrentlyReservedException e)
            {
                ModelState.AddModelError("model.StartDate", "Podana data została już zarezerwowana!");
                return(BadRequest(ModelState));
            }
            catch (Exception e)
            {
                _logger.Error(e);
                return(InternalServerError());
            }
        }
Exemple #2
0
        public IActionResult CreateVisit(int catID)
        {
            var cat = dbContext.Cats.FirstOrDefault(c => c.ID == catID);

            ViewBag.CatName = cat.Name;
            var pageInject = new AddVisitBindingModel {
                Vets = dbContext.Vets.ToList().GetViewModels()
            };

            return(View(pageInject));
        }
Exemple #3
0
        public IActionResult CreateVisit(AddVisitBindingModel bindingModel, int catID)
        {
            var visitToCreate = new Visit
            {
                VisitDate = DateTime.Now,
                Vet       = dbContext.Vets.FirstOrDefault(v => v.ID == bindingModel.VetID),
                Cat       = dbContext.Cats.FirstOrDefault(c => c.ID == catID)
            };

            dbContext.Visits.Add(visitToCreate);
            dbContext.SaveChanges();
            return(RedirectToAction("Index"));
        }