Ejemplo n.º 1
0
        public ActionResult SingleSnippet(string guid)
        {
            var viewModel = new SnippetDetailsModel();
            var userId = -1;
            Guid userGuid;
            try
            {
                SnippetDTO snippet = _managerService.GetSnippet(guid);
                userId = snippet.User_Id;
                userGuid = snippet.User_FormsAuthId;

                if (snippet != null)
                {
                    UserDTO user = _managerService.UserDetails(snippet.User_Id, snippet.Guid);
                    if (user == null)
                    {
                        TempData["Error"] = "Error getting user information for snippet";
                        return View(viewModel);
                    }

                    viewModel = new SnippetDetailsModel
                                    {
                                        Data = Encoding.UTF8.GetString(snippet.Data),
                                        PreviewData = Encoding.UTF8.GetString(snippet.PreviewData),
                                        SnippetId = snippet.Guid,
                                        Name = snippet.Name,
                                        Description = snippet.Description,
                                        SnippetUrl = snippet.Guid.ToString(),
                                        UserId = snippet.User_Id,
                                        UserGuid = user.FormsAuthId,
                                        UserName = user.LoginName,
                                        UserAvatar = user.AvatarImage,
                                        Hyperlinks = new List<HyperlinkDTO>(),
                                        Files = new List<NamedFileWithDescription>()
                                    };
                    HyperlinkDTO[] hyperlinks = _managerService.GetHyperlinksForSnippet(snippet.Guid, user.Id,
                                                                                        user.FormsAuthId);
                    if (hyperlinks != null && hyperlinks.Any())
                        viewModel.Hyperlinks = hyperlinks;

                    FileDTO[] files = _managerService.GetFilesForSnippet(snippet.Guid, user.Id, user.FormsAuthId);
                    if (files != null && files.Any())
                    {
                        foreach (NamedFileWithDescription file in files.Select(fileDTO => new NamedFileWithDescription
                                                                                              {
                                                                                                  File = fileDTO,
                                                                                                  Name = fileDTO.Name,
                                                                                                  Description =
                                                                                                      fileDTO.
                                                                                                      Description
                                                                                              }))
                        {
                            ((List<NamedFileWithDescription>) viewModel.Files).Add(file);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.LogError("Snippet exception", ex);
                TempData["Error"] = "Unknow error occurred.";
                return RedirectToAction("All");
            }

            // If the user has opted to receive notifications, add one now
            var newMessage = new NotificationDTO
                                 {
                                     User_Id = userId,
                                     User_FormsAuthId = userGuid,
                                     NotificationType_Id = 1,
                                     Text = "Your snipppet (Id: " + guid + ") has been viewed.",
                                     DateCreated = DateTime.UtcNow
                                 };
            _managerService.CreateNewUserNotification(newMessage);

            return View(viewModel);
        }
Ejemplo n.º 2
0
        public ActionResult Profile(UserModel.EditUserProfileModel model, HttpPostedFileBase image)
        {
            UserDTO details = _managerService.UserDetails(model.UserId, model.UserGuid);
            if (details != null)
            {
                details.Id = model.UserId;
                details.FormsAuthId = model.UserGuid;
                details.Email = model.Email;
                details.AvatarImage = (image != null) ? new byte[image.ContentLength] : details.AvatarImage;
                if (image != null) image.InputStream.Read(details.AvatarImage, 0, image.ContentLength);
            }

            try
            {
                bool result = _managerService.UpdateUserDetails(details);
                if (result)
                {
                    // Send notification
                    var notification = new NotificationDTO
                                           {
                                               NotificationType_Id = 1,
                                               User_FormsAuthId = model.UserGuid,
                                               User_Id = model.UserId,
                                               Text = "Your profile settings were updated",
                                               DateCreated = DateTime.UtcNow
                                           };
                    _managerService.CreateNewUserNotification(notification);

                    TempData["Message"] = "User settings saved";
                    return RedirectToAction("Profile", model);
                }
                else
                {
                    TempData["Error"] = "Error saving data";
                    return View(model);
                }
            }
            catch (Exception ex)
            {
                Logger.LogError("Error saving user profile data. User image too large.", ex);
                TempData["Error"] = "Error saving user profile data. User image too large.";
                return View(model);
            }
        }