示例#1
0
 public ActionResult Edit([Bind(Include = "MajorId,Name,MetaTitle,Description,CreateDate,CreateBy,ModifyDate,ModifyBy")] Major major, HttpPostedFileBase uploadFile)
 {
     if (ModelState.IsValid)
     {
         FileUploadService service = new FileUploadService();
         var session = (UserLogin)Session[CommonConstants.USER_SESSION];
         if (uploadFile != null)
         {
             FileDetail file = db.FileDetails.ToList().Find(x => x.MajorId == major.MajorId);
             if (file != null)
             {
                 file.FileName        = Path.GetFileName(uploadFile.FileName);
                 file.ContentType     = uploadFile.ContentType;
                 file.Data            = service.ConvertToBytes(uploadFile);
                 db.Entry(file).State = EntityState.Modified;
             }
             else
             {
                 db.FileDetails.Add(new FileDetail
                 {
                     FileName    = Path.GetFileName(uploadFile.FileName),
                     ContentType = uploadFile.ContentType,
                     Data        = service.ConvertToBytes(uploadFile),
                     MajorId     = major.MajorId
                 });
             }
         }
         major.ModifyBy        = session.Username;
         major.ModifyDate      = DateTime.Now;
         db.Entry(major).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(major));
 }
示例#2
0
        public ActionResult editProfile([Bind(Include = "UserId,Name,Email,Username,Password,Phone,Address,DateOfBirth,CreateDate,CreateBy,ModifyDate,ModifyBy,AccountStatus,GroupId,MajorId")] User user, HttpPostedFileBase uploadFile)
        {
            if (ModelState.IsValid)
            {
                FileUploadService service = new FileUploadService();
                var session = (UserLogin)Session[CommonConstants.USER_SESSION];
                if (uploadFile != null)
                {
                    FileDetail file = db.FileDetails.ToList().Find(x => x.UserId == user.UserId);
                    if (file != null)
                    {
                        file.FileName        = Path.GetFileName(uploadFile.FileName);
                        file.ContentType     = uploadFile.ContentType;
                        file.Data            = service.ConvertToBytes(uploadFile);
                        db.Entry(file).State = EntityState.Modified;
                    }
                    else
                    {
                        db.FileDetails.Add(new FileDetail
                        {
                            FileName    = Path.GetFileName(uploadFile.FileName),
                            ContentType = uploadFile.ContentType,
                            Data        = service.ConvertToBytes(uploadFile),
                            UserId      = user.UserId
                        });
                    }
                }
                user.ModifyBy   = session.Username;
                user.ModifyDate = DateTime.Now;
                var Password = Request["Password"];
                ViewBag.GroupId = new SelectList(db.GroupMembers, "GroupId", "Name", user.GroupId);
                ViewBag.MajorId = new SelectList(db.Majors, "MajorId", "Name", user.MajorId);


                var email          = Request["Email"];
                var checkEmailNull = db.Users.Where(x => x.UserId.Equals(user.UserId) && x.Email.Equals(email)).Count();
                if (checkEmailNull <= 0)
                {
                    var isEmailExist = db.Users.Where(s => s.Email == email).Count();
                    if (isEmailExist > 0)
                    {
                        ModelState.AddModelError("", "Email already exists.");
                        return(View(user));
                    }
                }

                var checkPass = db.Users.Where(x => x.UserId == user.UserId && x.Password == Password).Count();
                if (checkPass <= 0)
                {
                    user.Password = Encryptor.GetMD5(Password);
                }

                db.Entry(user).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Profile", new { id = user.UserId }));
            }
            return(View(user));
        }
示例#3
0
        public ActionResult Create([Bind(Include = "MajorId,Name,MetaTitle,Description,CreateDate,CreateBy,ModifyDate,ModifyBy")] Major major, HttpPostedFileBase uploadFile)
        {
            if (ModelState.IsValid)
            {
                var session = (UserLogin)Session[CommonConstants.USER_SESSION];
                FileUploadService service = new FileUploadService();
                if (uploadFile != null)
                {
                    db.FileDetails.Add(new FileDetail
                    {
                        FileName    = Path.GetFileName(uploadFile.FileName),
                        ContentType = uploadFile.ContentType,
                        Data        = service.ConvertToBytes(uploadFile),
                        MajorId     = major.MajorId
                    });
                }
                major.CreateBy   = session.Username;
                major.CreateDate = DateTime.Now;
                db.Majors.Add(major);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(major));
        }
示例#4
0
        public ActionResult Create([Bind(Include = "TopicId,Name,MetaTitle,Description,DisplayOrder,ClosureDate,CreateDate,CreateBy,ModifyDate,ModifyBy,Status,MajorId")] Topic topic, HttpPostedFileBase uploadFile)
        {
            if (ModelState.IsValid)
            {
                var session = (UserLogin)Session[CommonConstants.USER_SESSION];
                FileUploadService service = new FileUploadService();
                if (uploadFile != null)
                {
                    db.FileDetails.Add(new FileDetail
                    {
                        FileName    = Path.GetFileName(uploadFile.FileName),
                        ContentType = uploadFile.ContentType,
                        Data        = service.ConvertToBytes(uploadFile),
                        TopicId     = topic.TopicId
                    });
                }
                topic.CreateBy   = session.Username;
                topic.CreateDate = DateTime.Now;
                db.Topics.Add(topic);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.MajorId = new SelectList(db.Majors, "MajorId", "Name", topic.MajorId);
            return(View(topic));
        }
示例#5
0
        public ActionResult ViewPostDetails(Post post, List <HttpPostedFileBase> postedFile)
        {
            if (ModelState.IsValid)
            {
                //New Files

                foreach (var file in postedFile)
                {
                    FileUploadService service = new FileUploadService();
                    if (file != null && file.ContentLength > 0)
                    {
                        FileDetail fileDetail = new FileDetail()
                        {
                            FileName    = Path.GetFileName(file.FileName),
                            ContentType = file.ContentType,
                            Data        = service.ConvertToBytes(file),
                            PostId      = post.PostId
                        };
                        db.Entry(fileDetail).State = EntityState.Added;
                    }
                }
                var session = (UserLogin)Session[CommonConstants.USER_SESSION];
                post.ModifyBy        = session.Username;
                post.ModifyDate      = DateTime.Now;
                db.Entry(post).State = EntityState.Modified;
                db.SaveChanges();
                ViewBag.EditPost = "This post has been edited successfully!";
                return(RedirectToAction("ViewListPost", new { id = post.TopicId }));
            }
            return(View(post));
        }
示例#6
0
 public ActionResult Create([Bind(Include = "UserId,Name,Email,Username,Password,Phone,Address,DateOfBirth,CreateDate,CreateBy,ModifyDate,ModifyBy,AccountStatus,GroupId,MajorId")] User user, FileDetail fileDetail, HttpPostedFileBase uploadFile)
 {
     if (ModelState.IsValid)
     {
         var session       = (UserLogin)Session[CommonConstants.USER_SESSION];
         var checkEmail    = db.Users.FirstOrDefault(s => s.Email == user.Email);
         var checkUsername = db.Users.FirstOrDefault(s => s.Username == user.Username);
         ViewBag.GroupId = new SelectList(db.GroupMembers, "GroupId", "Name", user.GroupId);
         ViewBag.MajorId = new SelectList(db.Majors, "MajorId", "Name", user.MajorId);
         if (checkEmail != null)
         {
             ModelState.AddModelError("", "Email already exists.");
             return(View());
         }
         else if (checkUsername != null)
         {
             ModelState.AddModelError("", "Username already exists.");
             return(View());
         }
         else
         {
             FileUploadService service = new FileUploadService();
             if (uploadFile != null)
             {
                 db.FileDetails.Add(new FileDetail
                 {
                     FileName    = Path.GetFileName(uploadFile.FileName),
                     ContentType = uploadFile.ContentType,
                     Data        = service.ConvertToBytes(uploadFile),
                     UserId      = user.UserId
                 });
             }
             if (user.GroupId == "Admin" || user.GroupId == "Manager")
             {
                 user.MajorId = null;
             }
             user.CreateBy   = session.Username;
             user.CreateDate = DateTime.Now;
             user.Password   = Encryptor.GetMD5(user.Password);
             db.Configuration.ValidateOnSaveEnabled = false;
             db.Users.Add(user);
             var result = db.SaveChanges();
             if (result > 0)
             {
                 ViewBag.Success = "Create Successfully!";
                 return(View());
             }
             else
             {
                 ModelState.AddModelError("", "Create unsuccessfully! Please try again.");
                 return(View());
             }
         }
     }
     return(View(user));
 }
示例#7
0
        public ActionResult EditPost(Post post, List <HttpPostedFileBase> postedFile)
        {
            if (ModelState.IsValid)
            {
                //New Files

                foreach (var file in postedFile)
                {
                    FileUploadService service = new FileUploadService();
                    if (file != null && file.ContentLength > 0)
                    {
                        FileDetail fileDetail = new FileDetail()
                        {
                            FileName    = Path.GetFileName(file.FileName),
                            ContentType = file.ContentType,
                            Data        = service.ConvertToBytes(file),
                            PostId      = post.PostId
                        };
                        db.Entry(fileDetail).State = EntityState.Added;
                    }
                }
                Service sendEmail = new Service();
                var     session   = (UserLogin)Session[CommonConstants.USER_SESSION];

                post.ModifyBy        = session.Username;
                post.ModifyDate      = DateTime.Now;
                db.Entry(post).State = EntityState.Modified;
                db.SaveChanges();

                Topic topic = db.Topics.Find(post.TopicId);
                var   user  = db.Users.ToList().Find(x => x.Username == topic.CreateBy);
                if (user != null)
                {
                    var receiver = user.Email;
                    var subject  = "Your student has submitted their post submission for your Topic";
                    var body     = "Hi " + user.Name + "\n Your student has submitted their post submission for your Topic\nTopic: " + topic.Name + "\nStudent's name: " + session.Name + "\nSubmit Date: " + DateTime.Now;
                    sendEmail.SendAutometicalEmail(receiver, subject, body);
                }


                ViewBag.EditPost = "This post has been edited successfully!";
                return(RedirectToAction("SubmitPosts", new { myPostsId = post.PostId }));
            }
            return(View(post));
        }
示例#8
0
        public ActionResult SubmitPosts(long?id, Post post, List <HttpPostedFileBase> postedFile)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            if (postedFile != null)
            {
                FileUploadService service   = new FileUploadService();
                Service           sendEmail = new Service();
                var session = (UserLogin)Session[CommonConstants.USER_SESSION];

                //Add file to Database
                List <FileDetail> fileDetails = new List <FileDetail>();
                foreach (var file in postedFile)
                {
                    FileDetail fileDetail = new FileDetail()
                    {
                        FileName    = Path.GetFileName(file.FileName),
                        ContentType = file.ContentType,
                        Data        = service.ConvertToBytes(file)
                    };
                    fileDetails.Add(fileDetail);
                }

                // Add Post
                Topic topic = db.Topics.Find(id);
                post.TopicId     = id;
                post.MajorId     = topic.MajorId;
                post.FileDetails = fileDetails;
                post.CreateBy    = session.Username;
                post.CreateDate  = DateTime.Now;
                db.Posts.Add(post);
                db.SaveChanges();

                var user     = db.Users.FirstOrDefault(x => x.Username == topic.CreateBy);
                var receiver = user.Email;
                var subject  = "Your student has submitted their post submission for your Topic";
                var body     = "Hi " + user.Name + "\n Your student has submitted their post submission for your Topic\nTopic: " + topic.Name + "\nStudent's name: " + session.Name + "\nSubmit Date: " + DateTime.Now;
                sendEmail.SendAutometicalEmail(receiver, subject, body);
                return(RedirectToAction("SubmitPosts"));
            }
            ViewBag.upLoadError = "You have not file yet!";
            return(View());
        }