Пример #1
0
        public ActionResult Create([Bind(Include = "id,question,answer,category_id")] faq faq)
        {
            try
            {
                if (Session["role"] != null)
                {
                    if (Session["role"].ToString() == "ADM" || Session["role"].ToString() == "PAT" || Session["role"].ToString() == "USR")
                    {
                        if (ModelState.IsValid)
                        {
                            if (Session["userId"] != null)
                            {
                                faq.publisher_id = Convert.ToInt32(Session["userId"]);
                            }
                            else
                            {
                                faq.publisher_id = 0;
                            }

                            faq.date_created = System.DateTime.Now;
                            db.faqs.Add(faq);
                            db.SaveChanges();
                            ViewBag.questionAdd = "Thank you for your question! Our staff will look into providing an asnwer!";

                            if (Session["role"].ToString() == "ADM")
                            {
                                return(RedirectToAction("Index"));
                            }
                        }

                        ViewBag.category_id = new SelectList(db.categories, "id", "name", faq.category_id);
                        //ViewBag.publisher_id = new SelectList(db.users, "id", "username", faq.publisher_id);
                        return(View(faq));
                    }
                }
                else
                {
                    return(View("~/Views/LabTestResults/NotLoggedIn.cshtml"));
                }
            }
            catch (DbUpdateException e) {
                ViewBag.DbExceptionMessage = e.Message;
            }
            catch (SqlException e)
            {
                ViewBag.SqlExceptionMessage = e.Message;
            }
            catch (Exception genericException)
            {
                ViewBag.ExceptionMessage = genericException.Message;
            }
            return(View("~/Views/Errors/Details.cshtml"));
        }
Пример #2
0
        public ActionResult Create([Bind(Include = "VolunteerID,FirstName,LastName,Dob,Phone,StAddress,Reason,skills,username,Email,dateavailable")] Volunteer volunteer)
        {
            if (ModelState.IsValid)
            {
                volunteer.username = Session["userName"].ToString();
                db.Volunteers.Add(volunteer);
                db.SaveChanges();
                return(RedirectToAction("ThankYou"));
            }

            return(View(volunteer));
        }
Пример #3
0
        public ActionResult Register(user user, FormCollection form)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    NSHNContext db = new NSHNContext();

                    //ENCRYPTION GOES HERE


                    //DETERMINE IF ADMIN TO SHOW THE OPTION OF CHOOSING ADMIN/USER STATUS
                    if (Session["role"] != null)
                    {
                        if (Session["role"].ToString() == "ADM")
                        {
                            user.user_role = form["user-role"];
                        }
                    }
                    else
                    {
                        user.user_role = "USR";
                    }

                    //DO NOT ALLOW A USERNAME TO BE REGISTERED TWICE
                    var users = db.users.Where(u => u.username == user.username);
                    foreach (var u in users)
                    {
                        if (u.username == user.username)
                        {
                            ViewBag.RegisterStatus = "This username has already been taken. Please choose another one.";
                            return(View("~/Views/Account/Register.cshtml"));
                        }
                    }

                    db.users.Add(user);
                    db.SaveChanges();

                    ModelState.Clear();
                    ViewBag.RegisterStatus = "user " + user.username + " Successfully registered!";
                    return(View("~/Views/Account/Register.cshtml"));
                }
            }
            catch (DbUpdateException e)
            {
                ViewBag.DbExceptionMessage = e.Message;
            }
            catch (SqlException e)
            {
                ViewBag.SqlExceptionMessage = e.Message;
            }
            catch (Exception e)
            {
                ViewBag.GenericException = e.Message;
            }
            return(View("~/Views/Navigate/Errors.cshtml"));
        }
Пример #4
0
        public void SaveImgCaption(int id, FormCollection form)
        {
            if (ModelState.IsValid)
            {
                //SAVE THE CAPTION FOR THE CORRECT IMAGE
                string caption = form["item.caption"].ToString();
                int    imgId   = Convert.ToInt16(form["item.id"]);

                //GET THE IMAGE PROPERTIES FROM THE IMG ID
                image articleImage = db.images.Find(imgId);

                //MODIFY THE IMAGE CAPTION
                articleImage.caption = caption;

                db.Entry(articleImage).State = EntityState.Modified;
                db.SaveChanges();
            }
        }
Пример #5
0
        public ActionResult Create(donation donation, FormCollection form)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    //CREATE A NEW USER

                    //DETERMINE IF THE USERNAME EXHISTS
                    var user_exhists = db.users.Where(u => u.username == donation.north_shore_accounts.user.username);
                    int count        = 0;
                    foreach (var u in user_exhists)
                    {
                        count += 1;
                    }

                    if (count > 0)
                    {
                        ViewBag.province_char = new SelectList(db.provinces, "code", "name");
                        ViewBag.ErrorMssg     = "This username has already been taken. Please choose another one.";
                        return(View("~/Views/donations/Create.cshtml"));
                    }

                    donation.north_shore_accounts.user.user_role = "USR";
                    db.users.Add(donation.north_shore_accounts.user);
                    db.SaveChanges();

                    db.payment_information.Add(donation.north_shore_accounts.payment_information);
                    db.SaveChanges();

                    //GET THE ID OF INSERTED PAYMENT INFORMATION AND SELECTED DROPDOWN THEN ADD NSA
                    donation.north_shore_accounts.payment_info  = donation.north_shore_accounts.payment_information.id;
                    donation.north_shore_accounts.user_id       = donation.north_shore_accounts.user.id;
                    donation.north_shore_accounts.province_char = form["province_char"];
                    db.north_shore_accounts.Add(donation.north_shore_accounts);
                    db.SaveChanges();

                    //GET THE ID OF THE INSERTED NSA ID AND ADD TO DONATIONS
                    donation.account_id = donation.north_shore_accounts.id;
                    db.donations.Add(donation);
                    db.SaveChanges();

                    if (Session["role"] != null)
                    {
                        if (Session["role"].ToString() == "ADM")
                        {
                            return(RedirectToAction("Index"));
                        }
                        else
                        {
                            ViewBag.province_char = new SelectList(db.provinces, "code", "name");
                            Session["donated"]    = "true";
                            ViewBag.SuccessMssg   = "This username has already been taken. Please choose another one.";
                            return(View("~/Views/donations/Create.cshtml"));
                        }
                    }

                    else
                    {
                        ViewBag.province_char = new SelectList(db.provinces, "code", "name");
                        Session["donated"]    = "true";
                        ViewBag.SuccessMssg   = "Thank you for your generous donation!";
                        return(View("~/Views/donations/Create.cshtml"));
                    }
                }
                //FOR MODEL STATE ERRORS - DEVELOPER ONLY
                var errors = ModelState.Select(x => x.Value.Errors)
                             .Where(y => y.Count > 0)
                             .ToList();

                ViewBag.province_char = new SelectList(db.provinces, "code", "name");
                return(View(donation));
            }
            catch (DbUpdateException e)
            {
                ViewBag.DbExceptionMessage = e.Message;
            }
            catch (SqlException e)
            {
                ViewBag.SqlExceptionMessage = e.Message;
            }
            catch (Exception e)
            {
                ViewBag.GenericException = e.Message;
            }

            return(View("~/Views/Navigate/Errors.cshtml"));
        }
Пример #6
0
        public void SaveImgCaption(int id, FormCollection form)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    //SAVE THE CAPTION FOR THE CORRECT IMAGE
                    string caption = form["item.caption"].ToString();
                    int    imgId   = Convert.ToInt16(form["item.id"]);

                    //GET THE IMAGE PROPERTIES FROM THE IMG ID
                    image articleImage = db.images.Find(imgId);

                    //MODIFY THE IMAGE CAPTION
                    articleImage.caption = caption;

                    db.Entry(articleImage).State = EntityState.Modified;
                    db.SaveChanges();
                }
            }
            catch (DbUpdateException e)
            {
                ViewBag.DbExceptionMessage = e.Message;
            }
            catch (SqlException e)
            {
                ViewBag.SqlExceptionMessage = e.Message;
            }
            catch (Exception e)
            {
                ViewBag.GenericException = e.Message;
            }
            RedirectToAction("Errors", "Navigate");
        }