public ActionResult CreateImage(TransportImageViewModel transport, HttpPostedFileBase file)
        {
            if (ModelState.IsValid)
            {
                var photoUrl = Upload(file);
                transport.DetailsIVM.PhotoUrl  = photoUrl.Substring(1, photoUrl.Length - 2);
                transport.DetailsIVM.GalleryId = transport.DetailsGVM.Id;
                transport.DetailsIVM.ProfileId = Guid.Parse(Session["UserId"].ToString());

                var client = GlobalWebApiClient.GetClient();

                var response = client.PostAsJsonAsync("/api/images/save/", transport.DetailsIVM).Result;
                try
                {
                    if (response.IsSuccessStatusCode)
                    {
                        //var gallery = responseGallery.Content.ReadAsAsync<TransportImageViewModel>().Result;
                        var ivm = response.Content.ReadAsAsync <ImageViewModel>().Result;

                        TempData["SuccessMessage"] = "Image created successfully";

                        return(RedirectToAction("Details", "Gallery", transport.DetailsGVM));
                    }
                }
                catch (Exception ex)
                {
                    var result = ex.Message;
                }
            }
            else
            {
                ModelState.AddModelError(string.Empty, "Server Error. Please contact administrator.");
            }
            return(RedirectToAction("Index", "Gallery"));
        }
        public ActionResult Details(Guid?id)
        {
            try
            {
                var client          = GlobalWebApiClient.GetClient();
                var responseGallery = client.GetAsync("api/galleries/gallery/info/" + id.ToString()).Result;

                if (responseGallery.IsSuccessStatusCode)
                {
                    var gallery = responseGallery.Content.ReadAsAsync <GalleryViewModel>().Result;

                    //var client = GlobalWebApiClient.GetClient();
                    var response     = client.GetAsync("/api/images/imagesbyuser").Result;
                    var responseUser = client.GetAsync("/api/Account/LoggedUser").Result;

                    if (responseUser.IsSuccessStatusCode && response.IsSuccessStatusCode)
                    {
                        IEnumerable <ImageViewModel> userImages;
                        userImages = response.Content.ReadAsAsync <IEnumerable <ImageViewModel> >().Result;
                        var loggedUser = responseUser.Content.ReadAsAsync <ProfileViewModel>().Result;

                        if (loggedUser.Id.ToString().Equals(Session["UserId"].ToString()))
                        {
                            ViewBag.PhotoCount   = userImages.ToList().Count;
                            ViewBag.ImagesByUser = userImages.ToList();
                            ViewBag.LoggedUser   = true;

                            var transport = new TransportImageViewModel
                            {
                                DetailsGVM = gallery
                            };


                            return(View(transport));
                        }
                        else
                        {
                            ViewBag.LoggedUser = false;
                        }
                    }
                }
                else
                {
                    return(View());
                }
            }
            catch (Exception ex)
            {
                var result = ex.Message;
            }
            return(View());
        }
        public ActionResult Create(GalleryViewModel gallery, HttpPostedFileBase file)
        {
            if (ModelState.IsValid)
            {
                var client = GlobalWebApiClient.GetClient();

                var photoUrl = Upload(file);
                gallery.PhotoUrl  = photoUrl.Substring(1, photoUrl.Length - 2);
                gallery.ProfileId = Guid.Parse(Session["UserId"].ToString());

                var response = client.PostAsJsonAsync("api/galleries/save/", gallery).Result;
                try
                {
                    if (response.IsSuccessStatusCode)
                    {
                        gallery = response.Content.ReadAsAsync <GalleryViewModel>().Result;

                        var transport = new TransportImageViewModel
                        {
                            DetailsGVM = gallery
                        };

                        TempData["SuccessMessage"] = "Gallery created successfully";
                        return(RedirectToAction("Details", transport.DetailsGVM));
                    }
                }
                catch (Exception ex)
                {
                    var result = ex.Message;
                }
            }
            else
            {
                ModelState.AddModelError(string.Empty, "Server Error. Please contact administrator.");
            }
            return(View(gallery));
        }