public ActionResult stepFour()
        {
            // If i change login to creat article id on begin submission then
            // also need to add login user in if statement as doing in else
            if (HttpContext.Session.GetInt32("articleId") != null)
            {
                int id = (int)HttpContext.Session.GetInt32("articleId");

                TempArticle tempArticle = dbContext.tempArticles.SingleOrDefault(ta => ta.Id == id);
                if (tempArticle.AuthorsEmails == null)
                {
                    tempArticle.AuthorsEmails = User.Identity.Name + "-;";
                }
                StepFourViewModel model = _mapper.Map <TempArticle, StepFourViewModel>(tempArticle);
                model.AuthorsEmails       = decodeStringToList(tempArticle.AuthorsEmails);
                model.AuthorsInstitutions = initializeUsersInstitutions(model.AuthorsEmails);

                return(View(model));
            }
            else
            {
                TempArticle article = new TempArticle()
                {
                    AuthorsEmails = User.Identity.Name + "-;"
                };
                dbContext.tempArticles.Add(article);
                dbContext.SaveChanges();
                HttpContext.Session.SetInt32("articleId", article.Id);
                return(RedirectToAction("stepfour"));
            }
        }
        public ActionResult StepFour(StepThreeViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("StepOne"));
            }

            var selectedMedicalCenterId = viewModel.SelectedMedicalCenter;
            var selectedDoctorId        = viewModel.SelectedDoctor;

            var allSchedules = db.AppointmentSchedules.ToList();

            var unavailableSchedules = from a in db.Appointments
                                       where a.DoctorId == selectedDoctorId
                                       &&
                                       a.MedicalCenterId == selectedMedicalCenterId
                                       &&
                                       a.Date == DateTime.Today
                                       select a;

            var availableSchedules = db.AppointmentSchedules.Where(s => !unavailableSchedules.Any(p => p.AppointmentScheduleId == s.Id));

            var nextViewModel = new StepFourViewModel
            {
                SelectedMedicalCenter = selectedMedicalCenterId,
                SelectedDoctor        = selectedDoctorId,
                AppointmentSchedules  = availableSchedules
            };

            return(View("StepFour", nextViewModel));
        }
        public ActionResult stepFour(StepFourViewModel model)
        {
            if (model.AuthorsEmails != null && model.AuthorsEmails.GroupBy(a => a).Any(c => c.Count() > 1))
            {
                ModelState.AddModelError("", "Same User Repeated");
            }
            if (model.AuthorsEmails != null && !model.AuthorsEmails.Contains(User.Identity.Name))
            {
                ModelState.AddModelError("", "Logged in user must be one of author");
                model.AuthorsEmails.Insert(0, User.Identity.Name);
            }
            if (!ModelState.IsValid)
            {
                model.AuthorsInstitutions = initializeUsersInstitutions(model.AuthorsEmails);
                return(View(model));
            }

            string coAuthorsEmails = "";

            foreach (var authorEmail in model.AuthorsEmails)
            {
                coAuthorsEmails += authorEmail + "-;";
            }

            if (HttpContext.Session.GetInt32("articleId") != null)
            {
                int id = (int)HttpContext.Session.GetInt32("articleId");

                TempArticle article = dbContext.tempArticles.SingleOrDefault(ta => ta.Id == id);
                article.AuthorsEmails = coAuthorsEmails;

                dbContext.SaveChanges();
            }
            else
            {
                TempArticle article = new TempArticle()
                {
                    AuthorsEmails = coAuthorsEmails
                };
                dbContext.tempArticles.Add(article);
                dbContext.SaveChanges();
                HttpContext.Session.SetInt32("articleId", article.Id);
            }
            return(RedirectToAction("stepFive"));
        }
        public ActionResult ConfirmAppointment(StepFourViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("StepOne"));
            }

            var selectedMedicalCenterId = viewModel.SelectedMedicalCenter;
            var selectedDoctorId        = viewModel.SelectedDoctor;
            var selectedSchedule        = viewModel.SelectedSchedule;

            var nextViewModel = new Appointment
            {
                MedicalCenterId       = (int)selectedMedicalCenterId,
                DoctorId              = (int)selectedDoctorId,
                AppointmentScheduleId = (int)selectedSchedule,
                Date                = DateTime.Today,
                Doctor              = db.Doctors.Find(selectedDoctorId),
                MedicalCenter       = db.MedicalCenters.Find(selectedMedicalCenterId),
                AppointmentSchedule = db.AppointmentSchedules.Find(selectedSchedule)
            };

            return(View("ConfirmAppointment", nextViewModel));
        }