Пример #1
0
        // GET: Agenda/Edit/5
        public ActionResult Edit(int id)
        {
            if (id <= 0)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Agenda agenda = db.Agenda.Find(id);

            if (agenda == null)
            {
                return(HttpNotFound());
            }
            //
            var agendaEditView = new AgendaEditView
            {
                AgendaId            = agenda.AgendaId,
                DataReserva         = agenda.DataReserva,
                DataReservaOriginal = agenda.DataReserva,
                Evento      = agenda.Evento,
                QtdePessoas = agenda.QtdePessoas
            };

            ViewBag.DataInicial = DateTime.Today.ToString("yyyy-MM-dd");
            ViewBag.DataFinal   = DateTime.Today.AddMonths(6).ToString("yyyy-MM-dd");
            return(View(agendaEditView));
        }
Пример #2
0
 public ActionResult Edit([Bind(Include = "AgendaId,DataReserva,DataReservaOriginal,Evento,QtdePessoas,UserId")] AgendaEditView agenda)
 {
     if (ModelState.IsValid)
     {
         if (agenda.DataReservaOriginal != agenda.DataReserva)
         {
             var JaExisteReserva = (from a in db.Agenda
                                    where a.DataReserva == agenda.DataReserva
                                    select 1).Count();
             if (JaExisteReserva > 0)
             {
                 ModelState.AddModelError("DataReserva", "Esta data já foi reservada! Favor escolher outra.");
             }
         }
         if (ModelState.IsValid)
         {
             var agendaModel = new Agenda
             {
                 AgendaId        = agenda.AgendaId,
                 UserId          = User.Identity.GetUserId(),
                 DataReserva     = agenda.DataReserva,
                 Evento          = agenda.Evento,
                 QtdePessoas     = agenda.QtdePessoas,
                 DataAtualizacao = DateTime.Now
             };
             db.Entry(agendaModel).State = EntityState.Modified;
             db.SaveChanges();
             return(RedirectToAction("Index"));
         }
     }
     return(View(agenda));
 }