예제 #1
0
        public ActionResult Create([Bind(Include = "User_Following,User_Followed")] Following following)
        {
            if (ModelState.IsValid)
            {
                db.Followings.Add(following);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.User_Following = new SelectList(db.Users, "User_ID", "First_Name", following.User_Following);
            ViewBag.User_Followed  = new SelectList(db.Users, "User_ID", "First_Name", following.User_Followed);
            return(View(following));
        }
예제 #2
0
        public ActionResult ProfilePicture(User model)
        {
            bool   Status  = false;
            string message = "";

            if (ModelState.IsValid)
            {
                using (memcombdbEntities dc = new memcombdbEntities())
                {
                    if (HttpContext.Request.Cookies["userIDCookie"] != null)
                    {
                        HttpCookie cookie = HttpContext.Request.Cookies.Get("userIDCookie");
                        var        v      = dc.Users.Where(a => a.Email_ID == cookie.Value).FirstOrDefault();
                        Directory.CreateDirectory(Server.MapPath("~/Users/User_ID_" + v.User_ID + "/Profile_Pic"));
                        HttpPostedFileBase file = model.Profile_Picture_imgPath;
                        if (file.ContentLength > 0)
                        {
                            var fileName = Path.GetFileName(file.FileName);
                            var path     = Path.Combine(Server.MapPath("~/Users/User_ID_" + v.User_ID + "/Profile_Pic"), fileName);
                            file.SaveAs(path);

                            /*model.User_ID = v.User_ID;
                             * model.First_Name = v.First_Name;
                             * model.Last_Name = v.Last_Name;
                             * model.Email_ID = v.Email_ID;
                             * model.Password = v.Password;*/
                            v.Profile_Picture = path;
                            //model.Background_Pic = v.Background_Pic;*/
                        }
                        dc.Users.Include(v.Profile_Picture);
                        try
                        {
                            dc.SaveChanges();
                        }
                        catch (DbEntityValidationException ex)
                        {
                            // Retrieve the error messages as a list of strings.
                            var errorMessages = ex.EntityValidationErrors
                                                .SelectMany(x => x.ValidationErrors)
                                                .Select(x => x.ErrorMessage);

                            // Join the list to a single string.
                            var fullErrorMessage = string.Join("; ", errorMessages);

                            // Combine the original exception message with the new one.
                            var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage);

                            // Throw a new DbEntityValidationException with the improved exception message.
                            throw new DbEntityValidationException(exceptionMessage, ex.EntityValidationErrors);
                        }
                        Status = true;
                    }
                }
            }
            else
            {
                message = "Invalid request";
            }
            return(RedirectToAction("Index"));
        }
예제 #3
0
        public ActionResult Biography(User model)
        {
            bool   Status  = false;
            string message = "";

            if (ModelState.IsValid)
            {
                using (memcombdbEntities dc = new memcombdbEntities())
                {
                    if (HttpContext.Request.Cookies["userIDCookie"] != null)
                    {
                        HttpCookie cookie = HttpContext.Request.Cookies.Get("userIDCookie");
                        var        v      = dc.Users.Where(a => a.Email_ID == cookie.Value).FirstOrDefault();
                        if (model.Biography.Length > 0 && model.Biography.Length <= 300)
                        {
                            v.Biography = model.Biography;
                        }
                        dc.Users.Include(v.Biography);
                        dc.SaveChanges();
                    }
                }
            }
            else
            {
                message = "Invalid request";
            }
            return(RedirectToAction("Index"));
        }
예제 #4
0
        public ActionResult Comment(Comment comment)
        {
            if (ModelState.IsValid)
            {
                using (memcombdbEntities db = new memcombdbEntities())
                {
                    HttpCookie cookie = HttpContext.Request.Cookies.Get("userIDCookie");
                    var        v      = db.Users.Where(a => a.Email_ID == cookie.Value).FirstOrDefault();

                    Comment newComment = new Comment()
                    {
                        User_ID         = v.User_ID,
                        Datetime_Posted = DateTime.Now,
                        Comment1        = comment.Comment1,
                        Memory_ID       = comment.Memory_ID
                    };

                    db.Comments.Add(newComment);
                    db.SaveChanges();
                }
            }


            return(RedirectToAction("Index"));
        }
예제 #5
0
        public ActionResult Index(/*[Bind(Exclude = "IsEmailVerified,ActivationCode")]*/ User user)
        {
            bool   Status  = false;
            string message = "";

            //
            // Model Validation
            if (ModelState.IsValid)
            {
                // Email already registered
                #region
                var isRegistered = IsEmailRegistered(user.Email_ID);
                if (isRegistered)
                {
                    ModelState.AddModelError("EmailRegistered", "Email already registered");
                    return(View(user));
                }
                #endregion

                /*
                 #region Generate Activation Code
                 * user.ActivationCode = Guid.NewGuid();
                 #endregion
                 */


                #region Password Hashing
                user.Password = Encrypt.Hash(user.Password);
                #endregion

                // user.IsEmailVerified = false;


                #region Save to database
                using (memcombdbEntities dc = new memcombdbEntities())
                {
                    dc.Users.Add(user);
                    dc.SaveChanges();

                    //Send confirmation email to user
                    SendVerificationLinkEmail(user.Email_ID, user.User_ID.ToString());
                    message = "Registration was successful. Check your email for verification link " +
                              "at your email: " + user.Email_ID;
                    Status = true;
                    Directory.CreateDirectory(Server.MapPath("~/Memories/User_ID" + user.User_ID));
                    return(View("~/Views/LogInPage/Index.cshtml"));
                }
                #endregion
            }
            else
            {
                message = "Invalid request";
            }

            ViewBag.Message = message;
            ViewBag.Status  = Status;
            return(View(user));
        }
예제 #6
0
        public ActionResult Index(/*[Bind(Exclude = "IsEmailVerified,ActivationCode")]*/ Memory model)
        {
            bool   Status  = false;
            string message = "";

            //
            // Model Validation

            if (ModelState.IsValid)
            {
                #region Save to database
                using (memcombdbEntities dc = new memcombdbEntities())
                {
                    if (HttpContext.Request.Cookies["userIDCookie"] != null)
                    {
                        HttpCookie cookie = HttpContext.Request.Cookies.Get("userIDCookie");
                        var        v      = dc.Users.Where(a => a.Email_ID == cookie.Value).FirstOrDefault();

                        int memoryIDForFolder = dc.Memories.Max(u => u.Memory_ID);
                        int fragmentIDPath    = dc.Fragments.Max(u => u.Fragment_ID);

                        memoryIDForFolder = memoryIDForFolder + 1;
                        fragmentIDPath    = fragmentIDPath + 1;

                        Memory newMemory = new Memory()
                        {
                            User_ID            = v.User_ID,
                            Date_Created       = DateTime.Now,
                            Memory_Title       = model.Memory_Title,
                            Memory_Description = model.Memory_Description
                        };

                        Directory.CreateDirectory(Server.MapPath("~/Memories/User_ID_" + v.User_ID + "/Memory_ID_" + memoryIDForFolder));

                        List <Fragment> fragmentList = new List <Fragment>();

                        var checkForHighlight = false;

                        foreach (Fragment frag in model.Fragments.ToList())
                        {
                            HttpPostedFileBase file = frag.getImagePath;

                            if (file.ContentLength > 0)
                            {
                                var fileName = Path.GetFileName(file.FileName);
                                var path     = Path.Combine(Server.MapPath("~/Memories/User_ID_" + v.User_ID + "/Memory_ID_" + memoryIDForFolder), fragmentIDPath + "_" + fileName);
                                file.SaveAs(path);

                                if (frag.Is_Highlight == true)
                                {
                                    checkForHighlight = true;
                                }

                                fragmentList.Add(new Fragment
                                {
                                    Fragment_Date      = frag.Fragment_Date,
                                    Fragment_Data      = path,
                                    Memory_Description = frag.Memory_Description,
                                    Fragment_Location  = frag.Fragment_Location,
                                    Is_Highlight       = frag.Is_Highlight
                                });
                            }
                        }

                        if (checkForHighlight == false)
                        {
                            var firstElement = fragmentList.First();
                            firstElement.Is_Highlight = true;
                        }

                        dc.Memories.Add(newMemory);
                        foreach (var frag in fragmentList)
                        {
                            dc.Fragments.Add(frag);
                        }
                        dc.SaveChanges();
                        Status = true;
                    }
                }
                #endregion
            }
            else
            {
                message = "Invalid request";
            }


            ViewBag.Message = message;
            ViewBag.Status  = Status;
            return(RedirectToAction("Index"));
        }