public ViewResult Edit(int id)
        {
            Participant Participant = _ParticipantRepository.GetById(id);
            ParticipantEditViewModel ParticipantEditViewModel = new ParticipantEditViewModel()
            {
                Id        = Participant.Id,
                FirstName = Participant.FirstName,
                LastName  = Participant.LastName,
                ClassCode = Participant.ClassCode,
                Email     = Participant.Email,
            };

            return(View(ParticipantEditViewModel));
        }
示例#2
0
        public ActionResult Edit(Participant participant, int studyMeetingId)
        {
            if (ModelState.IsValid)
            {
                db.Entry(participant).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Add", new { id = studyMeetingId }));
            }
            var model = new ParticipantEditViewModel();

            model.StudyMeetingId = studyMeetingId;
            model.Participant    = participant;
            return(View(model));
        }
        public IActionResult Edit(ParticipantEditViewModel model)
        {
            if (ModelState.IsValid)
            {
                Participant Participant = _ParticipantRepository.GetById(model.Id);

                Participant.FirstName = model.FirstName;
                Participant.LastName  = model.LastName;
                Participant.ClassCode = model.ClassCode;
                Participant.Email     = model.Email;
                _ParticipantRepository.Edit(Participant);
                return(RedirectToAction("Details", new { id = model.Id }));
            }
            return(View(model));
        }
示例#4
0
        public IActionResult Edit()
        {
            int participantId = Int32.Parse(HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value);

            Participant participant = _participantRepository.GetById(participantId);

            ParticipantEditViewModel viewModel = new ParticipantEditViewModel
            {
                Id        = participant.Id,
                Name      = participant.Name,
                Email     = participant.Email,
                Birthdate = participant.Birthdate,
                Gender    = participant.Gender
            };

            return(View(viewModel));
        }
        public IHttpActionResult PostParticipant(ParticipantEditViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var meeting = db.StudyMeetings.Find(model.StudyMeetingId);

            if (meeting == null)
            {
                return(BadRequest(string.Format("Not found study meeting.(StudyMeetingId={0})", model.StudyMeetingId)));
            }

            meeting.Participants.Add(model.Participant);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = model.Participant.Id }, model));
        }
示例#6
0
        public IActionResult Update(ParticipantEditViewModel model, int id)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    int participantId = Int32.Parse(HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value);

                    if (participantId != id)
                    {
                        ModelState.AddModelError("Email", "Participante não encontrado.");

                        return(View("Edit", model));
                    }

                    Participant participant = _participantRepository.GetById(id);

                    participant.Name      = model.Name;
                    participant.Birthdate = model.Birthdate;
                    participant.Gender    = model.Gender;

                    if (model.Password != null)
                    {
                        participant.Password = HashExtension.Create(model.Password, Environment.GetEnvironmentVariable("AUTH_SALT"));
                    }

                    _participantRepository.Update(participant);
                    _participantRepository.SaveChanges();

                    TempData["Success"] = "Dados do participante atualizado com sucesso!";

                    return(RedirectToAction("Edit"));
                }
            }
            catch (Exception exception)
            {
                TempData["Error"] = "Internal server error";
                _logger.LogError("Participant update error: " + exception);
            }

            return(View("Edit", model));
        }
示例#7
0
        // GET: /Participant/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Participant participant = db.Participants.Find(id);

            if (participant == null)
            {
                return(HttpNotFound());
            }

            var model = new ParticipantEditViewModel();

            model.StudyMeetingId = participant.StudyMeeting.Id;
            model.Participant    = participant;

            return(View(model));
        }