public ActionResult Register(mvcForumapp.Models.Register user, HttpPostedFileBase file)
        {
            if (ModelState.IsValid)
            {
                if (file == null)
                {
                    ModelState.AddModelError("File", "Please Upload Your file");
                }
                else if (file.ContentLength > 0)
                {
                    int MaxContentLength = 1024 * 1024 * 3; //3 MB
                    string[] AllowedFileExtensions = new string[] { ".jpg", ".gif", ".png", ".pdf" };

                    if (!AllowedFileExtensions.Contains(file.FileName.Substring(file.FileName.LastIndexOf('.'))))
                    {
                        ModelState.AddModelError("File", "Please file of type: " + string.Join(", ", AllowedFileExtensions));
                    }

                    else if (file.ContentLength > MaxContentLength)
                    {
                        ModelState.AddModelError("File", "Your file is too large, maximum allowed size is: " + MaxContentLength + " MB");
                    }
                    else
                    {
                        using (var db = new newForumDBEntities())
                        {
                            Byte[] imgByte = null;
                            HttpPostedFileBase File = file;
                            //Create byte Array with file len
                            imgByte = new Byte[File.ContentLength];
                            //force the control to load data in array
                            File.InputStream.Read(imgByte, 0, File.ContentLength);
                            var userdets = db.tblUsers.CreateObject();
                            userdets.UserName = user.Username;
                            userdets.DateJoined = DateTime.Now;
                            userdets.DisplayName = user.Displayname;
                            userdets.EmailID = user.Email;
                            userdets.Password = user.password;
                            userdets.Photo = imgByte;
                            //var encrppass = Encrypt(user.password, true);
                            //var userdets = db.tblUsers.CreateObject();
                            //userdets.EmailID = user.Email;
                            //userdets.password = encrppass;

                            db.tblUsers.AddObject(userdets);
                            db.SaveChanges();
                            return RedirectToAction("Index", "Technology");
                        }
                    }
                }

            }
            return View(user);
        }
Ejemplo n.º 2
0
 public ActionResult Login(mvcForumapp.Models.userModel user)
 {
     if (ModelState.IsValid)
     {
         if (isValid(user.Email, user.password))
         {
             var user1 = db.tblUsers.FirstOrDefault(u => u.EmailID == user.Email).UserName;
             Session["UserName"] = user1;
             //FormsAuthentication.SetAuthCookie(user.Email, false);
             return RedirectToAction("Index", "Technology");
         }
         else
         {
             ModelState.AddModelError("", "Login Data is Incorrect");
         }
     }
     return View(user);
 }
Ejemplo n.º 3
0
        public ActionResult PostReply(mvcForumapp.Models.Replys reply)
        {
            int repcnt = 0;
            int quesID = 0;
            int techID = 0;
            if (ModelState.IsValid)
            {
                using (var db = new newForumDBEntities())
                {
                    quesID = Convert.ToInt16(Request.QueryString["QuestionID"].ToString());
                    techID = Convert.ToInt16(Request.QueryString["TechID"].ToString());
                    var postrep = db.tblReplies.CreateObject();
                    postrep.TechID = Convert.ToInt16(Request.QueryString["TechID"].ToString());
                    postrep.QuestionID = Convert.ToInt16(Request.QueryString["QuestionID"].ToString());
                    postrep.date = DateTime.Now;
                    postrep.ReplyMsg = reply.ReplyContent;
                    postrep.UserName = Session["UserName"].ToString();
                    db.tblReplies.AddObject(postrep);
                    db.SaveChanges();
                    var paramQuesID = new SqlParameter("@QuestionID", SqlDbType.Int);
                    var paramRepCnt = new SqlParameter("@Repcount", SqlDbType.Int);
                    paramQuesID.Value = quesID;
                    var repcount = db.tblQuestions.Where(e1 => e1.QuestionID == quesID).FirstOrDefault();
                    repcnt = repcount.ReplyCount;

                    if (repcnt == 0)
                    {
                        repcnt++;
                        paramRepCnt.Value = repcnt;
                        var v = db.ExecuteStoreCommand("UPDATE tblQuestions SET ReplyCount = @Repcount WHERE QuestionID = @QuestionID", paramRepCnt, paramQuesID);
                    }
                    else
                    {
                        repcnt = repcnt + 1;
                        paramRepCnt.Value = repcnt;
                        var v = db.ExecuteStoreCommand("UPDATE tblQuestions SET ReplyCount = @Repcount WHERE QuestionID = @QuestionID", paramRepCnt, paramQuesID);
                    }

                    return RedirectToAction("displayQuestionwithAnswers", "Question_Answer", new { QuestionID = quesID });
                }
            }
            return View(reply);
        }
 public ActionResult PostQuestion(mvcForumapp.Models.Questions user)
 {
     int techID = 0;
     if (ModelState.IsValid)
     {
         techID = Convert.ToInt16(Request.QueryString["TechID"].ToString());
         using (var db = new newForumDBEntities())
         {
             var userdets = db.tblQuestions.CreateObject();
             userdets.TechID = Convert.ToInt16(Request.QueryString["TechID"].ToString());
             userdets.QuestionTitle = user.TopicTitle;
             userdets.QuestionDesc = user.TopicContent;
             userdets.DatePosted = DateTime.Now;
             userdets.UserName = Session["UserName"].ToString();
             userdets.viewCount = 0;
             userdets.ReplyCount = 0;
             db.tblQuestions.AddObject(userdets);
             db.SaveChanges();
             return RedirectToAction("DisplayQuestions", "Technology", new { TechID = techID });
         }
     }
     return View(user);
 }