Beispiel #1
0
        public async Task <HttpResponseMessage> AddIcon(IncomingBase64File model)
        {
            return(await ErrorFactory.Handle(async() =>
            {
                var userID = User.Identity.GetUserId();

                if (userID == null)
                {
                    throw new Exception();
                }

                using (var unitOfWork = new UnitOfWork())
                {
                    try
                    {
                        if (model != null && !string.IsNullOrWhiteSpace(model.Data))
                        {
                            //This is added to help yogita with her base64 problems.
                            model.Data = model.Data.Replace(' ', '+');


                            var data = ImageFactory.ConvertBase64ToArray(model.Data);

                            GalleryManager galMan = new GalleryManager();

                            var pictureId = await galMan.UploadImage(data, userID, ImageFormat.Png);

                            if (pictureId == null)
                            {
                                throw new Exception();
                            }

                            var icon = unitOfWork.Pictures.CreateIconLink(userID, pictureId ?? Guid.NewGuid());

                            unitOfWork.Complete();


                            return JsonFactory.CreateJsonMessage(OutgoingIcon.Parse(icon), HttpStatusCode.OK, this.Request);
                        }
                    }
                    catch (Exception)
                    {
                        //Maybe try to delete image.
                    }

                    return JsonFactory.CreateJsonMessage(new OutgoingMessage {
                        Action = "unknownError"
                    }, HttpStatusCode.InternalServerError, this.Request);
                }
            }, this.Request));
        }
Beispiel #2
0
        public static OutgoingVenueItems Parse(VenueItems x)
        {
            if (x == null)
            {
                return(null);
            }

            return(new OutgoingVenueItems
            {
                Id = x.Id,
                Name = x.Name,
                Price = x.Price,
                Type = OutgoingVenueItemType.Parse(x.ItemTypes),
                IconId = x.IconId,
                Icon = OutgoingIcon.Parse(x.Icons),
                IsHidden = x.IsHidden
            });
        }
Beispiel #3
0
        public HttpResponseMessage GetIcon(int iconId)
        {
            return(ErrorFactory.Handle(() =>
            {
                var userID = User.Identity.GetUserId();

                if (userID == null)
                {
                    throw new Exception();
                }

                using (var unitOfWork = new UnitOfWork())
                {
                    var icon = unitOfWork.Pictures.GetIconLink(userID, iconId);

                    return JsonFactory.CreateJsonMessage(OutgoingIcon.Parse(icon), HttpStatusCode.OK, this.Request);
                }
            }, this.Request));
        }
Beispiel #4
0
        public HttpResponseMessage GetIcons()
        {
            return(ErrorFactory.Handle(() =>
            {
                var userID = User.Identity.GetUserId();

                if (userID == null)
                {
                    throw new Exception();
                }

                using (var unitOfWork = new UnitOfWork())
                {
                    var icons = unitOfWork.Pictures.GetAllIcons(userID);

                    var outgoingIcons = icons?.Select(x => OutgoingIcon.Parse(x))?.ToList();

                    return JsonFactory.CreateJsonMessage(outgoingIcons, HttpStatusCode.OK, this.Request);
                }
            }, this.Request));
        }