public ActionResult Index(/*[Bind(Exclude = "IsEmailVerified,ActivationCode")]*/ User user)
        {
            bool   Status  = false;
            string message = "";

            //
            // Model Validation
            if (ModelState.IsValid)
            {
                #region Save to database
                using (memcombdbEntities dc = new memcombdbEntities())
                {
                    Status = true;
                    return(View());
                }
                #endregion
            }
            else
            {
                message = "Invalid request";
            }

            ViewBag.Message = message;
            ViewBag.Status  = Status;
            return(View(user));
        }
示例#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 bool IsEmailRegistered(string emailID)
 {
     using (memcombdbEntities dc = new memcombdbEntities())
     {
         var v = dc.Users.Where(a => a.Email_ID == emailID).FirstOrDefault();
         return(v != null);
     }
 }
示例#6
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));
        }
示例#7
0
        // GET: Profile/Details/5
        public ActionResult Details(int id)
        {
            using (memcombdbEntities db = new memcombdbEntities())
            {
                if (HttpContext.Request.Cookies["userIDCookie"] != null)
                {
                    HttpCookie cookie = HttpContext.Request.Cookies.Get("userIDCookie");
                    var        v      = db.Users.Where(a => a.Email_ID == cookie.Value).FirstOrDefault();
                    //id = v.Email_ID;

                    //var data = db.Followings.Include(f => f.User).Where(f => f.User.Email_ID == id);

                    // var followed_user = db.Followings.Where(a => a.User_Followed == v.User_ID).FirstOrDefault();

                    // var get_UserID = db.Followings.Where(a => a.User_Followed == v.User_ID).FirstOrDefault();


                    var first_name = "default f_name";

                    var last_name = "default l_name";

                    /*var new_following = new Following()
                     * {
                     *  User_Following = get_UserID.User_Following,
                     *  User_Followed = get_UserID.User_Followed,
                     *  User_Followed_First_Name = first_name,
                     *  User_Followed_Last_Name = last_name
                     * };
                     *
                     * var user_following_join = db.Users.Join(db.Followings,
                     *  x => x.User_ID,
                     *  y => y.User_Followed,
                     *  (x, y) => new {
                     *      User_First_Name = x.First_Name,
                     *      User_Last_Name = x.Last_Name
                     *  }); */

                    return(View());
                }
                else
                {
                    var followings = db.Followings.Include(f => f.User);

                    return(View(followings.ToList()));
                }
            }

            //return View();
        }
        public ActionResult Login(UserLogin login, string ReturnUrl)
        {
            string message = "";

            using (memcombdbEntities dc = new memcombdbEntities())
            {
                var v = dc.Users.Where(a => a.Email_ID == login.Email_ID).FirstOrDefault();
                if (v != null)
                {
                    login.Password = Encrypt.Hash(login.Password);
                    if (string.Compare(login.Password, v.Password) == 0)
                    {
                        int timeout = login.RememberMe ? 525600 : 20;

                        HttpCookie userIDCookie = new HttpCookie("userIDCookie", login.Email_ID);

                        userIDCookie.Expires = DateTime.Now.AddMinutes(timeout);
                        Response.Cookies.Add(userIDCookie);

                        var    ticket    = new FormsAuthenticationTicket(login.Email_ID, login.RememberMe, timeout);
                        string encrypted = FormsAuthentication.Encrypt(ticket);
                        var    cookie    = new HttpCookie(FormsAuthentication.FormsCookieName, encrypted);
                        cookie.Expires  = DateTime.Now.AddMinutes(timeout);
                        cookie.HttpOnly = true;
                        Response.Cookies.Add(cookie);

                        if (Url.IsLocalUrl(ReturnUrl))
                        {
                            return(Redirect(ReturnUrl));
                        }
                        else
                        {
                            return(RedirectToAction("Index", "HomePage"));
                        }
                    }
                    else
                    {
                        message = "Invalid password provided";
                    }
                }
                else
                {
                    message = "Invalid credential provided";
                }
            }

            ViewBag.Message = message;
            return(View());
        }
示例#9
0
        // GET: Profile
        public ActionResult Index()
        {
            List <Following> followingList = new List <Following>();
            var followingCount             = 0;

            User user = new User();

            using (memcombdbEntities dc = new memcombdbEntities())
            {
                if (HttpContext.Request.Cookies["userIDCookie"] != null)
                {
                    var cookie = HttpContext.Request.Cookies.Get("userIDCookie");
                    var v      = dc.Users.Where(a => a.Email_ID == cookie.Value);
                    var data   = dc.Followings.Where(f => f.User.Email_ID == cookie.Value);

                    foreach (var u in v)
                    {
                        user.First_Name = u.First_Name;
                        user.Last_Name  = u.Last_Name;
                        user.Memories   = u.Memories;
                        if (u.Profile_Picture != null)
                        {
                            var temp = u.Profile_Picture.Replace(@"C:\Users\17347\Desktop\Capstone Project\Github\MemcombRepo\Memcomb", "~");
                            user.Profile_Picture = temp;
                        }
                        else
                        {
                            user.Profile_Picture = @"~\Users\Default\Profile_Pic\rename.jpg";
                        }
                        if (u.Background_Pic != null)
                        {
                            var temp = u.Background_Pic.Replace(@"C:\Users\17347\Desktop\Capstone Project\Github\MemcombRepo\Memcomb", "~");
                            user.Background_Pic = temp;
                        }
                        else
                        {
                            user.Background_Pic = @"~\Users\Default\Background_Pic\default.jpg";
                        }
                        if (u.Biography != null)
                        {
                            user.Biography = u.Biography;
                        }
                        user.Memories = u.Memories;
                    }

                    foreach (var item in data)
                    {
                        followingCount = followingCount + 1;
                        var followed_user_id = dc.Users.Where(b => b.User_ID == item.User_Followed).FirstOrDefault();
                        followingList.Add(new Following
                        {
                            User_Followed            = item.User_Followed,
                            User_Following           = item.User_Following,
                            User_Followed_First_Name = followed_user_id.First_Name,
                            User_Followed_Last_Name  = followed_user_id.Last_Name,
                            User = user,
                        });
                    }
                    ViewBag.followingCount = followingCount;
                    ViewBag.memoryCount    = user.Memories.Count;

                    user.Followings = followingList;
                }
            }
            //ProfilePageModel profiler = new ProfilePageModel();
            return(View(user));
        }
示例#10
0
        // GET: HomePage
        public ActionResult Index()
        {
            memcombdbEntities db = new memcombdbEntities();

            List <User>     userList     = new List <User>();
            List <Memory>   memoryList   = new List <Memory>();
            List <Fragment> fragmentList = new List <Fragment>();
            List <Comment>  commentList  = new List <Comment>();


            foreach (var u in db.Users)
            {
                User user = db.Users.Find(u.User_ID);

                var getProFilePic = "";

                if (u.Profile_Picture != null)
                {
                    var temp = u.Profile_Picture.Replace(@"C:\Users\17347\Desktop\Capstone Project\Github\MemcombRepo\Memcomb", "");
                    getProFilePic = temp;
                }
                else
                {
                    getProFilePic = @"\Users\Default\Profile_Pic\rename.jpg";
                }

                var m = db.Memories.Where(a => a.User_ID == u.User_ID);
                foreach (var item in m)
                {
                    Memory mem = db.Memories.Find(item.Memory_ID);

                    var v = db.Fragments.Where(a => a.Memory_ID == item.Memory_ID);

                    foreach (var s in v)
                    {
                        fragmentList.Add(new Fragment
                        {
                            Memory_ID          = s.Memory_ID,
                            Fragment_ID        = s.Fragment_ID,
                            Fragment_Date      = s.Fragment_Date,
                            Fragment_Data      = s.Fragment_Data,
                            Memory_Description = s.Memory_Description,
                            Fragment_Location  = s.Fragment_Location,
                            Is_Highlight       = s.Is_Highlight
                        });
                    }

                    var x = db.Comments.Where(a => a.Memory_ID == item.Memory_ID);

                    foreach (var com in x)
                    {
                        var y = db.Users.Find(com.User_ID);
                        commentList.Add(new Comment
                        {
                            Memory_ID = mem.Memory_ID,
                            Comment1  = com.Comment1,
                            firstName = y.First_Name,
                            lastName  = y.Last_Name
                        });
                    }


                    memoryList.Add(new Memory
                    {
                        User_ID            = mem.User_ID,
                        getFirstName       = user.First_Name,
                        getLastName        = user.Last_Name,
                        getProfilePic      = getProFilePic,
                        Memory_ID          = mem.Memory_ID,
                        Memory_Title       = mem.Memory_Title,
                        Memory_Description = mem.Memory_Description,
                        Date_Created       = mem.Date_Created,
                        Comments           = commentList,
                        Fragments          = fragmentList
                    });
                }

                userList.Add(new User
                {
                    User_ID    = u.User_ID,
                    First_Name = u.First_Name,
                    Last_Name  = u.Last_Name,
                    memoryList = memoryList
                });
            }

            memoryList = memoryList.OrderBy(e => e.Date_Created).ToList();

            return(View(memoryList));
            //return View(test);
        }
示例#11
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"));
        }