Exemplo n.º 1
0
        public ActionResult Accept(int id)
        {
            var StepReq = ssr.GetById(id);

            if (StepReq.Type == "Add")
            {
                Step step = new Step();
                step.StepDate             = StepReq.NewStepDate;
                step.StepDescription      = StepReq.NewStepDescription;
                step.StepSpeciality       = StepReq.NewStepSpeciality;
                step.TreatmentId          = StepReq.NewTreatmentId;
                step.Validation           = false;
                step.NbModifications      = 0;
                step.LastModificationBy   = StepReq.NewLastModificationBy;
                step.LastModificationDate = StepReq.NewLastModificationDate;
                step.ModificationReason   = "No modifications yet";
                ss.Add(step);
                ss.Commit();
                ssr.Delete(StepReq);
                ssr.Commit();
            }
            else if (StepReq.Type == "Update")
            {
                Step step = ss.GetById(StepReq.StepId);
                step.StepDate             = StepReq.NewStepDate;
                step.StepDescription      = StepReq.NewStepDescription;
                step.StepSpeciality       = StepReq.NewStepSpeciality;
                step.TreatmentId          = StepReq.NewTreatmentId;
                step.Validation           = StepReq.NewValidation;
                step.NbModifications     += 1;
                step.LastModificationBy   = StepReq.NewLastModificationBy;
                step.LastModificationDate = StepReq.NewLastModificationDate;
                step.ModificationReason   = StepReq.NewModificationReason;
                ss.Update(step);
                ss.Commit();
                ssr.Delete(StepReq);
                ssr.Commit();
            }

            return(Redirect(Request.UrlReferrer.ToString()));
        }
Exemplo n.º 2
0
        public ActionResult Edit(int id, StepViewModel collection)
        {
            try
            {
                var docteurreferant = st.GetById(ss.GetById(id).TreatmentId).DoctorId;
                if (docteurreferant != Int32.Parse(User.Identity.GetUserId()))
                {
                    var s = ss.GetById(id);
                    TempData["idTreatment"] = s.TreatmentId;

                    TempData["idPatient"] = st.GetById(s.TreatmentId).PatientId;
                    StepRequest sr = new StepRequest();
                    sr.NewLastModificationBy   = Int32.Parse(User.Identity.GetUserId());
                    sr.NewLastModificationDate = DateTime.UtcNow.Date;
                    sr.NewModificationReason   = collection.NewModificationReason;
                    sr.NewTreatmentId          = s.TreatmentId;

                    sr.NewStepDate        = collection.NewStepDate;
                    sr.NewStepDescription = collection.NewStepDescription;
                    sr.NewStepSpeciality  = collection.NewStepSpeciality;
                    sr.StepId             = id;
                    if (collection.NewValidation == "Valid")
                    {
                        sr.NewValidation = true;
                    }
                    else
                    {
                        sr.NewValidation = false;
                    }
                    sr.Type = "Update";
                    ssr.Add(sr);
                    ssr.Commit();
                    //MAIL
                    var maildocteur     = us.GetUserById(st.GetById(s.TreatmentId).DoctorId).Email;
                    var mailpatient     = us.GetUserById(st.GetById(s.TreatmentId).PatientId).Email;
                    var lastmodifbyname = us.GetUserById(Int32.Parse(User.Identity.GetUserId())).FirstName + " " + us.GetUserById(Int32.Parse(User.Identity.GetUserId())).LastName;
                    var illness         = st.GetById(s.TreatmentId).Illness;
                    var patient         = us.GetUserById(st.GetById(s.TreatmentId).PatientId).FirstName + " " + us.GetUserById(st.GetById(s.TreatmentId).PatientId).LastName;

                    MailMessage mail = new MailMessage("*****@*****.**", maildocteur, "Modification request", "The doctor '" + lastmodifbyname + "' sent a request to modify the treatment of '" + illness + "' of the patient '" + patient + "'");
                    mail.IsBodyHtml = true;
                    SmtpClient smtpClient = new SmtpClient("Smtp.gmail.com", 587);
                    smtpClient.EnableSsl = true;

                    smtpClient.Credentials = new System.Net.NetworkCredential("*****@*****.**", "epionepidev123");
                    smtpClient.Send(mail);
                    //!MAIL

                    return(RedirectToAction("Details", "Treatment", new { id = s.TreatmentId }));
                }
                else
                {
                    var s = ss.GetById(id);
                    TempData["idPatient"]   = st.GetById(s.TreatmentId).PatientId;
                    TempData["idTreatment"] = s.TreatmentId;
                    s.StepId               = s.StepId;
                    s.LastModificationBy   = Int32.Parse(User.Identity.GetUserId());
                    s.LastModificationDate = DateTime.UtcNow.Date;
                    s.ModificationReason   = collection.NewModificationReason;

                    s.StepDate        = collection.NewStepDate;
                    s.StepDescription = collection.NewStepDescription;
                    s.StepSpeciality  = collection.NewStepSpeciality;

                    s.NbModifications += 1;
                    if (collection.NewValidation == "Valid")
                    {
                        s.Validation = true;
                    }
                    else
                    {
                        s.Validation = false;
                    }
                    ss.Update(s);
                    ss.Commit();
                    return(RedirectToAction("Details", "Treatment", new { id = s.TreatmentId }));
                }
            }
            catch
            {
                return(View());
            }
        }