コード例 #1
0
        public IActionResult Edit(int id) //get info before editting
        {
            var appointment = _appointmentService.GetById(id);

            if (appointment == null)
            {
                return(NotFound());
            }
            var model = new AppointmentEditModelView()
            {
                Id                = appointment.Id,
                TechnicianId      = appointment.TechnicianId,
                TechnicianName    = appointment.TechnicianName,
                Observations      = appointment.Observations,
                StartDate         = appointment.StartDate,
                ExpectedFinalDate = appointment.ExpectedFinalDate,
                Address           = appointment.Address,
                AppointmentName   = appointment.AppointmentName,
                City              = appointment.City,
                District          = appointment.District,
                Number            = appointment.Number,
                Postcode          = appointment.Postcode,
                State             = appointment.State
            };

            return(View(model));
        }
コード例 #2
0
        public async Task <IActionResult> Edit(AppointmentEditModelView model)
        {
            if (model.StartDate >= model.ExpectedFinalDate)
            {
                ModelState.AddModelError("StartDate", "A data de início deve ser anterior à data de término");
                return(View());
            }
            if (model.StartDate < DateTime.Today)
            {
                ModelState.AddModelError("StartDate", "A data de início deve ser posterior à data atual");
                return(View());
            }
            if (ModelState.IsValid)
            {
                var appointment = _appointmentService.GetById(model.Id);
                if (appointment == null)
                {
                    return(NotFound());
                }

                appointment.Observations      = model.Observations;
                appointment.StartDate         = model.StartDate;
                appointment.ExpectedFinalDate = model.ExpectedFinalDate;
                appointment.Address           = model.Address;
                appointment.AppointmentName   = model.AppointmentName;
                appointment.City     = model.City;
                appointment.District = model.District;
                appointment.Number   = model.Number;
                appointment.Postcode = model.Postcode;
                appointment.State    = model.State;

                await _appointmentService.UpdateAsync(appointment);

                return(RedirectToAction(nameof(Index)));
            }
            return(View());
        }