Ejemplo n.º 1
0
        public ActionResult Create([Bind(Include = "QuestionId,UserId,FirstName,Email,Title,Message")] Question question)
        {
            if (ModelState.IsValid)
            {
                db.Questions.Add(question);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(question));
        }
Ejemplo n.º 2
0
        public ActionResult Create([Bind(Include = "VolonteerId,UserId,FirstName,Email,Message")] Volonteer volonteer)
        {
            if (ModelState.IsValid)
            {
                db.Volonteers.Add(volonteer);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(volonteer));
        }
Ejemplo n.º 3
0
        public ActionResult Create([Bind(Include = "UserId,LastName,FirstName,Email,LoginId,Image,last_name,RoleId")] User user)
        {
            if (ModelState.IsValid)
            {
                db.Users.Add(user);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.LoginId = new SelectList(db.Logins, "Id", "UserLogin", user.LoginId);
            ViewBag.RoleId  = new SelectList(db.Roles, "Id", "RoleName", user.RoleId);
            return(View(user));
        }
Ejemplo n.º 4
0
        public ActionResult Create(Comment comment)
        {
            //   this.Request
            if (ModelState.IsValid)
            {
                comment.UserId = (int)this.Session["CurrentUser"];
                comment.Date   = DateTime.Now;

                db.Comments.Add(comment);
                db.SaveChanges();
                return(RedirectToAction("Details", "Posts", new { id = comment.PostId }));
            }

            ViewBag.UserId = new SelectList(db.Users, "UserId", "LastName", comment.UserId);
            return(View(comment));
        }
Ejemplo n.º 5
0
        public ActionResult UpoladPictures(HttpPostedFileBase uploadImage)
        {
            using (var binaryReader = new BinaryReader(uploadImage.InputStream))
            {
                Random r        = new Random();
                string fileName = $"/Content/images/Gallery/{r.Next()}{uploadImage.FileName}";
                string savePath = $"{Request.PhysicalApplicationPath}{fileName}";
                System.IO.File.WriteAllBytes(savePath, binaryReader.ReadBytes(uploadImage.ContentLength));

                int  CurrentUserId = (int)this.Session["CurrentUser"];
                User user          = db.Users.First(u => u.UserId == CurrentUserId);
                user.Image = fileName;
                db.SaveChanges();
            }
            return(RedirectToAction("PersonalCabinet"));
        }
Ejemplo n.º 6
0
        public ActionResult CreateVolonteer(Volonteer volonteer)
        {
            if (ModelState.IsValid)
            {
                if (this.Session["IsAuth"] != null && (bool)this.Session["IsAuth"] == true)
                {
                    volonteer.FirstName = (string)this.Session["CurrentUserName"];
                    volonteer.Email     = (string)this.Session["CurrentUserEmail"];
                    volonteer.UserId    = (int?)this.Session["CurrentUser"];
                }


                db.Volonteers.Add(volonteer);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View());
        }
Ejemplo n.º 7
0
        public override void CreateRole(string roleName)
        {
            Role newRole = new Role()
            {
                RoleName = roleName
            };
            DomesticViolenceContext db = new DomesticViolenceContext();

            db.Roles.Add(newRole);
            db.SaveChanges();
        }
Ejemplo n.º 8
0
        public MembershipUser CreateUser(string lastname, string firstname, string login, byte[] password, string Role)
        {
            MembershipUser membershipUser = GetUser(login, false);

            if (membershipUser == null)
            {
                try
                {
                    using (DomesticViolenceContext db = new DomesticViolenceContext())
                    {
                        db.Logins.Add(
                            new Models.Login
                        {
                            UserLogin = login,
                            Password  = password
                        });
                        db.SaveChanges();

                        User user = new User
                        {
                            LastName  = lastname,
                            FirstName = firstname,
                            LoginId   = db.Logins.AsEnumerable().Last().Id,
                            RoleId    = 2
                        };
                        db.Users.Add(user);
                        db.SaveChanges();
                        return(GetUser(login, false));
                    }
                }
                catch (Exception)
                {
                    return(null);
                }
            }
            return(null);
        }
Ejemplo n.º 9
0
        public ActionResult LeaveComment(Comment comment)
        {
            if (ModelState.IsValid)
            {
                //var a = db.Posts.ToList();

                //var post = a.OrderByDescending(x => x.Date).Take(2).ToArray();
                //return PartialView("RecentBlogs", post);
                db.Comments.Add(comment);
                db.SaveChanges();
                Comment AddedComment = db.Comments.Add(comment);
                AddedComment.User.FirstName = (((string)this.Session["CurrentUserName"]));
                AddedComment.User.LastName  = (((string)this.Session["CurrentUserLastName"]));

                return(PartialView("LeaveComment", comment));

                //return View("Details", AddedComment);
            }

            ViewBag.PostId = comment.PostId;

            ViewBag.UserId = new SelectList(db.Users, "UserId", "LastName", comment.UserId);
            return(View(comment));
        }
Ejemplo n.º 10
0
        public ActionResult Create(NeedHelpUser needHelpUser)
        {
            if (ModelState.IsValid)
            {
                needHelpUser.Image  = (string)this.Session["Image"];
                needHelpUser.UserId = (int)this.Session["CurrentUser"];
                needHelpUser.Date   = DateTime.Now;
                db.NeedHelpUsers.Add(needHelpUser);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.UserId = new SelectList(db.Users, "UserId", "LastName", needHelpUser.UserId);
            return(View(needHelpUser));
        }
Ejemplo n.º 11
0
        public ActionResult Create(Donation donation)
        {
            if (ModelState.IsValid)
            {
                //using (var binaryReader = new BinaryReader(uploadImage.InputStream))
                //{
                //    Random r = new Random();
                //    string fileName = $"/Content/images/{r.Next()}{uploadImage.FileName}";
                //    string savePath = $"{Request.PhysicalApplicationPath}{fileName}";
                //    System.IO.File.WriteAllBytes(savePath, binaryReader.ReadBytes(uploadImage.ContentLength));
                //    donation.Image = fileName;
                //}
                donation.Image  = (string)this.Session["Image"];
                donation.UserId = (int)this.Session["CurrentUser"];
                donation.Date   = DateTime.Now;
                db.Donations.Add(donation);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.UserId = new SelectList(db.Users, "UserId", "LastName", donation.UserId);
            return(View(donation));
        }