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"); }
public PrivateCabinetModel GetPrivateCabinet(int userId) { var user = context.UserProfiles.FirstOrDefault(u => u.UserId == userId); if (user.UserProperty == null) SetPrivateProperties(user.UserId); var result = new PrivateCabinetModel { isAvatarExist = user.ImageData == null ? false : true, RegistrationDate = user.RegistrationDate, Email = user.UserProperty.ShowEmail ? (string.IsNullOrEmpty(user.Email) ? "пользователь не указал почту" : user.Email) : "пользователь скрыл почту", Mobile = user.UserProperty.ShowMobile ? (string.IsNullOrEmpty(user.Mobile) ? "пользователь не указал телефон" : user.Mobile) : "пользователь скрыл телефон" }; var query = context.Likes.Where(lk=>lk.Comment.UserId == userId); if (query == null || query.Count() == 0) result.UserRating = 0; else result.UserRating = query.Sum(x => x.Vote); return result; }