Ejemplo n.º 1
0
        public ActionResult CreateGroup(GroupViewModel collection)
        {
            string             creatorId = User.Identity.GetUserId();
            HttpPostedFileBase file      = collection.myGroup.groupPic;
            string             directory = @"~/Content/Images/";
            string             path      = null;
            string             fileName  = null;

            if (file != null && file.ContentLength > 0)
            {
                WebImage img = new WebImage(file.InputStream);
                if (img.Width > 300)
                {
                    img.Resize(300, 300);
                }
                fileName = Guid.NewGuid().ToString() + System.IO.Path.GetExtension(file.FileName);
                path     = Path.Combine(Server.MapPath(directory), fileName);
                img.Save(path);
            }

            var groupName        = collection.myGroup.groupName;
            var groupDescription = collection.myGroup.groupDescription;

            var myGroupRepo = new GroupRepository();

            int groupId = myGroupRepo.AddGroupToDb(groupName, groupDescription, path, creatorId);

            var groupView = new GroupViewModel();

            groupView.groupId = groupId;

            return(RedirectToAction("GroupPage", new
            {
                id = groupId
            }));
        }