Exemplo n.º 1
0
        public ActionResult Add(int id)
        {
            var model = new DocumentBindingModel();

            model.GuestId = id;

            return(this.View(model));
        }
Exemplo n.º 2
0
        public async Task <ActionResult> Add(DocumentBindingModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(model));
            }

            try
            {
                await this.documentsService.AddAsync(model);
            }
            catch (Exception ex)
            {
                this.ModelState.AddModelError(string.Empty, ex.Message);
                return(this.View(model));
            }

            return(this.Redirect("/Reservations/MyReservations"));
        }
Exemplo n.º 3
0
        public async Task AddAsync(DocumentBindingModel model)
        {
            Guest guest = this.guestRepository.All()
                          .FirstOrDefault(g => g.Id == model.GuestId);

            if (guest.DocumentId == null)
            {
                Document document = new Document
                {
                    Type       = model.Type,
                    IssueDate  = model.IssueDate,
                    ExpireDate = model.ExpireDate,
                    Number     = model.Number,
                    GuestId    = model.GuestId,
                };

                await this.documentRepository.AddAsync(document);

                await this.documentRepository.SaveChangesAsync();

                guest.Document = document;
                await this.guestRepository.SaveChangesAsync();
            }
        }