Example #1
0
        public ActionResult UploadGroupImage(HttpPostedFileBase file, int groupId)
        {
            var group = this.Data.Group.Find(groupId);

            if (group == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.NotFound));
            }

            var uploadedFile = FileUploadHelper.UploadFile(file, PhotoType.GroupImage);
            var loggedUserId = this.User.Identity.GetUserId();

            var photo = new GroupPhoto
            {
                AuthorId       = loggedUserId,
                DatePosted     = DateTime.Now,
                Name           = uploadedFile.Name,
                GroupPhotoType = GroupPhotoType.Overview
            };

            group.GroupPhotos.Add(photo);

            this.Data.Group.Update(group);
            this.Data.SaveChanges();

            return(RedirectToAction("Edit", new { groupId = groupId }));
        }
        /// <summary>
        /// Handles the Click event of the btnUpload control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void btnUpload_Click(object sender, EventArgs e)
        {
            if (CurrentUserSession == null || (CurrentGroupMember == null && !CurrentUserSession.IsAdmin())) 
                return;

            string name = Config.Misc.EnableBadWordsFilterGroups ? Parsers.ProcessBadWords(txtName.Text.Trim()) : txtName.Text.Trim();
            string description = Config.Misc.EnableBadWordsFilterGroups ? Parsers.ProcessBadWords(txtDescription.Text.Trim()) : txtDescription.Text.Trim();

            if (name.Length == 0)
            {
                lblError.Text = Lang.Trans("Please enter name");
                return;
            }

            if (description.Length == 0)
            {
                lblError.Text = Lang.Trans("Please enter description");
                return;
            }

            if (fuGroupPhoto.PostedFile.FileName.Length > 0)
            {
                GroupPhoto groupPhoto = new GroupPhoto(GroupID, CurrentUserSession.Username);

                try
                {
                    groupPhoto.Image = System.Drawing.Image.FromStream(fuGroupPhoto.PostedFile.InputStream);    
                }
                catch
                {
                    lblError.Text = Lang.Trans("Invalid image!");
                    return;
                }

                groupPhoto.Name = name;
                groupPhoto.Description = description;

                groupPhoto.Save();

                string cacheFileDir = Config.Directories.ImagesCacheDirectory + "/" + groupPhoto.ID % 10;
                string cacheFileMask = String.Format("groupPhoto{0}_*.jpg", groupPhoto.ID);
                foreach (string file in Directory.GetFiles(cacheFileDir, cacheFileMask))
                {
                    File.Delete(file);
                }

                #region Add NewGroupPhoto Event

                Event newEvent = new Event(CurrentUserSession.Username);

                newEvent.FromGroup = GroupID;
                newEvent.Type = Event.eType.NewGroupPhoto;
                NewGroupPhoto newGroupPhoto = new NewGroupPhoto();
                newGroupPhoto.GroupPhotoID = groupPhoto.ID;
                newEvent.DetailsXML = Misc.ToXml(newGroupPhoto);

                newEvent.Save();

                Group group = Group.Fetch(groupPhoto.GroupID);
                string[] usernames = User.FetchMutuallyFriends(CurrentUserSession.Username);

                foreach (string friendUsername in usernames)
                {
                    if (Config.Users.NewEventNotification)
                    {
                        if (group != null)
                        {
                            string text =
                                    String.Format("Your friend {0} has uploaded a new photo in the {1} group".Translate(),
                                                  "<b>" + CurrentUserSession.Username + "</b>", Server.HtmlEncode(group.Name));
                            string thumbnailUrl = GroupImage.CreateImageUrl(groupPhoto.ID, 50, 50, true);
                            User.SendOnlineEventNotification(CurrentUserSession.Username, friendUsername, text,
                                                             thumbnailUrl,
                                                             UrlRewrite.CreateShowGroupPhotosUrl(group.ID.ToString()));
                        }
                    }
                }

                GroupMember[] groupMembers = GroupMember.Fetch(GroupID, true);

                foreach (GroupMember groupMember in groupMembers)
                {
                    if (groupMember.Username == CurrentUserSession.Username) continue;

                    if (Config.Users.NewEventNotification)
                    {
                        if (group != null)
                        {
                            string text =
                                        String.Format("There is a new photo in the {0} group".Translate(),
                                                      "<b>" + Parsers.ProcessGroupName(group.Name) + "</b>");
                            string thumbnailUrl = GroupImage.CreateImageUrl(groupPhoto.ID, 50, 50, true);
                            User.SendOnlineEventNotification(CurrentUserSession.Username, groupMember.Username, text,
                                                             thumbnailUrl,
                                                             UrlRewrite.CreateShowGroupPhotosUrl(group.ID.ToString()));
                        }
                    }
                }

                #endregion

                Response.Redirect(UrlRewrite.CreateShowGroupPhotosUrl(GroupID.ToString()));
            }
        }
Example #3
0
		public void OrderByColumnInChildTableWorks()
		{
			Group group = new Group();
			group.Update();

			10.Times(i => CreatePhotoInGroup(group.K, i));
			var orderBy = new KeyValuePair<object, OrderBy.OrderDirection>(GroupPhoto.Columns.DateTime, OrderBy.OrderDirection.Descending);
			DateTime prevDate = DateTime.MaxValue;
			foreach (Photo p in group.ChildPhotos(orderBy))
			{
				DateTime d = new GroupPhoto(group.K, p.K).DateTime;
				Assert.Greater(prevDate, d);
				prevDate = d;
			}
		}