public ActionResult Edit(AppoitmentEditViewModel Vmodel, Appointment model) { if (!ModelState.IsValid) { return(View(model)); } Appointment appointment = service.Get(model.Id); appointment.StartDateTime = Convert.ToDateTime(model.StartDateTime); appointment.UserId = appointment.UserId; appointment.Activities.Clear(); List <Activity> ac = new List <Activity>(); foreach (var item in Vmodel.Activities) { if (item.IsChecked) { ac.Add(activityService.Get(item.Id)); } } appointment.Activities = ac; appointment.EndDateTime = model.StartDateTime.AddHours(ac.Sum(a => a.Duration)); if (!service.Update(appointment)) { return(View(model)); } return(RedirectToAction("Index")); }
public ActionResult Details(int id) { ViewModels.Appointment.AppoitmentEditViewModel model = new AppoitmentEditViewModel(); Appointment appointment = service.Get(id); if (appointment == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } else if (appointment.UserId != Authentication.AuthenticationManager.LoggedUser.Id && Authentication.AuthenticationManager.LoggedUser.IsAdmin != true) { return(RedirectToAction("Index", "Home")); } model.Id = appointment.Id; model.Username = appointment.User.Name; model.StartDateTime = appointment.StartDateTime.ToString(); model.EndDateTime = appointment.EndDateTime.ToString(); model.Activities = new List <ViewModels.CheckBoxView.ListCheckBoxViewModel>(); foreach (var item in appointment.Activities) { model.Activities.Add(new ViewModels.CheckBoxView.ListCheckBoxViewModel() { Id = item.Id, Name = item.Name, IsChecked = true, }); } foreach (var item in activityService.GetAll().Except(appointment.Activities)) { model.Activities.Add(new ViewModels.CheckBoxView.ListCheckBoxViewModel() { Id = item.Id, Name = item.Name, IsChecked = false, }); } return(View(model)); }