public ActionResult Index(HttpPostedFileBase file, UploadingPictureViewModel model)
        {
            if (file != null && file.ContentLength > 0)
                try
                {
                    string cookie = HttpContext.Request.Cookies["sessionId"].Value;
                    var userId = SessionHelper.GetAuthorizedUser(cookie);
                    if (userId == null)
                        return View("~//Views//Shared//Error.cshtml", new ErrorViewModel() { Message = "Unauthorized", StatusCode = HttpStatusCode.Unauthorized });

                    PictureClient pictureClient = new PictureClient();
                    var picture = new PictureDto() { AuthorId = userId.Value, Description = model.Description, Title = model.Name };
                    picture.PictureContent = PictureHelper.GetBytesFromStream(file);
                    picture.FileFormat = file.ContentType;
                    var resp = pictureClient.Create(picture, cookie);
                    ViewBag.Message = "File uploaded successfully";
                }
                catch (Exception ex)
                {
                    return View("~//Views//Shared//Error.cshtml", new ErrorViewModel() { Message = ex.Message, StatusCode = HttpStatusCode.ServiceUnavailable });
                }
            else
            {
                ViewBag.Message = "You have not specified a file.";
            }

            var picturesModel = GetPictures();
            if (picturesModel == null)
                return View("~//Views//Shared//Error.cshtml", new ErrorViewModel() { Message = "Unauthorized", StatusCode = HttpStatusCode.Unauthorized });
            return View("~//Views//MyPictures//Index.cshtml", picturesModel);
        }
        private PicturesViewModel GetPictures(int page = 1)
        {
            var picturesModel = new PicturesViewModel();
            PictureClient pictureClient = new PictureClient();

            var resp = pictureClient.Get(page, PerPage);
            picturesModel.ImageList.AddRange(PictureHelper.GetPictureData(resp.Items));
            picturesModel.PagingInfo = new PagingInfo()
            {
                CurrentPage = 1,
                ItemsPerPage = PerPage,
                TotalItems = resp.TotalItems
            };
            return picturesModel;
        }
 private PicturesViewModel GetPictures(int page = 1)
 {
     var picturesModel = new PicturesViewModel();
     PictureClient pictureClient = new PictureClient();
     string cookie = HttpContext.Request.Cookies["sessionId"].Value;
     ;
     var userId = SessionHelper.GetAuthorizedUser(cookie);
     if (userId == null) return null;
     var resp = pictureClient.GetByUser(userId.Value, page, PerPage);
     picturesModel.ImageList.AddRange(PictureHelper.GetPictureData(resp.Items));
     picturesModel.PagingInfo = new PagingInfo()
     {
         CurrentPage = 1,
         ItemsPerPage = PerPage,
         TotalItems = resp.TotalItems
     };
     return picturesModel;
 }
        public ActionResult Details(long id)
        {
            try
            {
                var currImage = new ViewPicture();
                var pictureClient = new PictureClient();
                var res = pictureClient.Get(id);
                currImage = new ViewPicture();
                var cont = Convert.ToBase64String(res.PictureContent.ToArray());
                cont = "data:" + res.FileFormat + ";base64," + cont;
                currImage.Contents = cont;
                currImage.Description = res.Description;
                currImage.Title = res.Title;
                currImage.Id = res.Id;
                return View("~//Views//Pictures//Details.cshtml", currImage);

            }
            catch (Exception e)
            {
                return View("~//Views//Shared//Error.cshtml", new ErrorViewModel() { Message = e.Message, StatusCode = HttpStatusCode.ServiceUnavailable });
            }
        }
 public ActionResult DeleteImage(long pictureId)
 {
     try
     {
         string cookie = HttpContext.Request.Cookies["sessionId"].Value;
         var userId = SessionHelper.GetAuthorizedUser(cookie);
         if (userId == null)
             return View("~//Views//Shared//Error.cshtml", new ErrorViewModel() { Message = "Unauthorized", StatusCode = HttpStatusCode.Unauthorized });
         PictureClient pictureClient = new PictureClient();
         pictureClient.Delete(pictureId, cookie);
         return Index();
     }
     catch (Exception e)
     {
         return View("~//Views//Shared//Error.cshtml", new ErrorViewModel() { Message = e.Message, StatusCode = HttpStatusCode.ServiceUnavailable });
     }
 }
 public ActionResult Details(long id)
 {
     try
     {
         Session["pictureId"] = id;
         var currImage = new ViewPicture();
         string cookie = HttpContext.Request.Cookies["sessionId"].Value;
         var userId = SessionHelper.GetAuthorizedUser(cookie);
         if (userId == null)
             return View("~//Views//Shared//Error.cshtml", new ErrorViewModel() {Message = "Unauthorized", StatusCode = HttpStatusCode.Unauthorized });
         PictureClient pictureClient = new PictureClient();
         var res = pictureClient.Get(id);
         currImage = new ViewPicture();
         string cont = Convert.ToBase64String(res.PictureContent.ToArray());
         cont = "data:" + res.FileFormat + ";base64," + cont;
         currImage.Contents = cont;
         currImage.Description = res.Description;
         currImage.Title = res.Title;
         currImage.Id = res.Id;
         return View("~//Views//MyPictures//Details.cshtml", currImage);
     }
     catch (Exception e)
     {
         return View("~//Views//Shared//Error.cshtml", new ErrorViewModel() { Message = e.Message, StatusCode = HttpStatusCode.ServiceUnavailable });
     }
 }
 public ActionResult ModifyN(ViewPicture model)
 {
     try
     {
         var id = (long) Session["pictureId"];
         string cookie = HttpContext.Request.Cookies["sessionId"].Value;
         var userId = SessionHelper.GetAuthorizedUser(cookie);
         if (userId == null)
             return View("~//Views//Shared//Error.cshtml", new ErrorViewModel() { Message = "Unauthorized", StatusCode = HttpStatusCode.Unauthorized });
         PictureClient pictureClient = new PictureClient();
         PictureDto p = new PictureDto();
         p.Id = id;
         p.Description = model.Description;
         p.Title = model.Title;
         pictureClient.Update(p, cookie);
         return Details(id);
     }
     catch (Exception e)
     {
         return View("~//Views//Shared//Error.cshtml", new ErrorViewModel() { Message = e.Message, StatusCode = HttpStatusCode.ServiceUnavailable });
     }
 }