public async Task <IHttpActionResult> Add(int groupID)
        {
            if (!Request.Content.IsMimeMultipartContent("form-data"))
            {
                return(BadRequest("Unsupported media type"));
            }


            var provider = new CustomMultipartFormDataStreamProvider(workingFolder);

            await Request.Content.ReadAsMultipartAsync(provider);

            var photos =
                provider.FileData
                .Select(file => new FileInfo(file.LocalFileName))
                .Select(fileInfo => fileInfo.Name).ToList();

            var ownerId = User.Identity.GetUserId();

            var imageIds = new List <int>();

            foreach (var path in photos)
            {
                imageIds.Add(ImageManager.AddImage(ownerId, groupID, path, DateTime.UtcNow));
            }

            var imageDetails = ImageManager.GetImagesForIds(User.Identity.GetUserId(), imageIds);

            PiChatHub.SendGroupNewImagesNotification(groupID, imageDetails);

            return(Ok(new { Message = "Photos uploaded ok" }));
        }
Beispiel #2
0
        public IHttpActionResult ChangeDescription(ChangeGroupDescriptionModel m)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            GroupManager.ChangeDescription(User.Identity.GetUserId(), m.GroupId, m.NewDescription);
            PiChatHub.SendChangeGroupDescriptionNotification(m.GroupId, m.NewDescription);
            return(Ok());
        }
Beispiel #3
0
        public IHttpActionResult RenameGroup(RenameGroupModel m)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            GroupManager.RenameGroup(User.Identity.GetUserId(), m.GroupId, m.NewName);
            PiChatHub.SendRenameGroupNotification(m.GroupId, m.NewName);
            return(Ok());
        }
        public IHttpActionResult ChangeDescription(ChangeDescriptionModel m)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var image = ImageManager.ChangeDescription(User.Identity.GetUserId(), m.ImageId, m.NewDescription);

            PiChatHub.SendGroupChangeImageDescriptionNotification(image.GroupId, image.ImageId, image.Description);
            return(Ok());
        }
Beispiel #5
0
        public IHttpActionResult DeleteGroup(int id)
        {
            var    paths         = ImageManager.GetImagePathsByGroup(id);
            string workingFolder = HttpRuntime.AppDomainAppPath + @"\Images";

            GroupManager.DeleteGroup(id, User.Identity.GetUserId());
            foreach (var path in paths)
            {
                File.Delete(Path.Combine(workingFolder, path));
            }



            PiChatHub.SendDeleteGroupNotification(id);
            return(Ok());
        }
        public IHttpActionResult DeleteImage(int ID)
        {
            string path = null;


            path = ImageManager.GetImagePathByID(ID, User.Identity.GetUserId());

            string workingFolder = HttpRuntime.AppDomainAppPath + @"\Images";

            var image = ImageManager.RemoveImage(ID, User.Identity.GetUserId());

            File.Delete(Path.Combine(workingFolder, path));
            PiChatHub.SendGroupDeleteImageNotification(image.GroupId, image.ImageId);


            return(Ok());
        }