Пример #1
0
        public ActionResult ChangeAvatar(PrivateCabinetModel model, HttpPostedFileBase file)
        {
            if (ModelState.IsValid)
            {
                if (file != null)
                {
                    using (var context = new SimpleMembershipContext())
                    {
                        var user = context.UserProfiles.FirstOrDefault(x => x.UserId == WebSecurity.CurrentUserId);

                        user.ImageData = new byte[file.ContentLength];
                        file.InputStream.Read(user.ImageData, 0, file.ContentLength);
                        user.ImageMimeType = file.ContentType;

                        context.SaveChanges();
                    }
                }
            }
            return RedirectToAction("Index");
        }
Пример #2
0
        public ActionResult _SubmitSectionChange(ChangeSectionModel section)
        {
            using (var context = new SimpleMembershipContext())
            {
                var db_section = context.Sections.FirstOrDefault(x => x.SectionId == section.SectionId);

                if (ModelState.IsValid)
                {
                    try
                    {
                        db_section.SectionTitle = section.SectionTitle;
                        context.SaveChanges();
                    }
                    catch
                    {
                        Response.StatusCode = (int)HttpStatusCode.BadRequest;
                    }
                }
                else
                {
                    section.SectionTitle = db_section.SectionTitle;
                    Response.StatusCode = (int)HttpStatusCode.BadRequest;
                }
            }
            return PartialView("_Section", section);
        }
Пример #3
0
        public bool RemoveUser(UserModel user)
        {
            var result = true;

            try
            {
                var roles = Roles.GetRolesForUser(user.UserName);
                if (roles != null && roles.Length != 0)
                {
                    Roles.RemoveUserFromRoles(user.UserName, roles);
                }

                using (var context = new SimpleMembershipContext())
                {
                    var toRemove = context.UserProfiles.FirstOrDefault(u => u.UserId == user.UserId);

                    toRemove.UserName = null;
                    toRemove.Email = null;
                    toRemove.ImageData = null;
                    toRemove.ImageMimeType = null;
                    toRemove.Mobile = null;

                    context.SaveChanges();
                }
            }
            catch
            {
                result = false;
            }
            return result;
        }
Пример #4
0
        public PartialViewResult _GetCommentData(CommentInfo model)
        {
            if (model.UserId != WebSecurity.CurrentUserId)
            {
                using (var context = new SimpleMembershipContext())
                {
                    var record = context.Likes.FirstOrDefault(l => l.UserId == WebSecurity.CurrentUserId && l.CommentId == model.CommentId);

                    if (record == null)
                    {
                        context.Likes.Add(new Like { CommentId = model.CommentId, UserId = WebSecurity.CurrentUserId, Vote = 1 });
                        model.CommentVote++;
                    }
                    else
                    {
                        if (record.Vote == 0)
                        {
                            record.Vote++;
                            model.CommentVote++;
                        }
                        else
                        {
                            model.CommentVote--;
                            record.Vote--;
                        }
                    }
                    context.SaveChanges();
                }
            }
            return PartialView("_GetCommentData", model);
        }