Пример #1
0
        public ContentResult AddPictureToAlbum(string albumId, string desc)
        {
            try
            {
                String userName = User.Identity.Name;
                if (m_model.aspnet_Users.Count(P => P.UserName.Equals(userName)) > 0)
                {
                    var user = m_model.aspnet_Users.Single(P => P.UserName.Equals(userName));
                    if (m_model.Albums.Count(P => P.Id.Equals(int.Parse(albumId))) <= 0)
                    {
                        return Content("{\"Status\":\"" + "false" + "\",\"Message\":\"" + "Album not found" + "\"}", "application/json");
                    }

                    var album = m_model.Albums.Single(P => P.Id.Equals(int.Parse(albumId)));

                    string tmpId = Guid.NewGuid().ToString();
                    var r = new List<ViewDataUploadFilesResult>();
                    foreach (string file in Request.Files)
                    {
                        PicOfAlbum newPicture = new PicOfAlbum();
                        HttpPostedFileBase hpf = Request.Files[file] as HttpPostedFileBase;
                        if (hpf.ContentLength == 0)
                            continue;

                        System.Drawing.Image bmp = System.Drawing.Bitmap.FromStream(hpf.InputStream);

                        string savedFileName = Path.Combine(Server.MapPath("~/Pics/Albums/Originals"), tmpId);
                        string savedThumbnailName = Path.Combine(Server.MapPath("~/Pics/Albums/Thumbnails"), tmpId);
                        bmp.Save(savedFileName + ".png", System.Drawing.Imaging.ImageFormat.Png);

                        double aspectRatio = 160.0 / (double)bmp.Width;

                        int width = (int)(160);
                        int height = (int)((double)bmp.Height * aspectRatio);
                        System.Drawing.Bitmap newPic = new System.Drawing.Bitmap(width, height);

                        System.Drawing.Graphics gr = System.Drawing.Graphics.FromImage(newPic);
                        gr.DrawImage(bmp, 0, 0, width, height);

                        newPic.Save(savedThumbnailName + ".png", System.Drawing.Imaging.ImageFormat.Png);

                        gr.Dispose();
                        newPic.Dispose();
                        bmp.Dispose();

                        r.Add(new ViewDataUploadFilesResult()
                        {
                            Name = tmpId + ".png",
                            Length = hpf.ContentLength,
                            Type = hpf.ContentType,
                            Id = 0
                        });

                        newPicture.AlbumId = album.Id;
                        newPicture.CreatorId = user.UserId;
                        newPicture.CreateDate = DateTime.Now;
                        newPicture.Desc = desc;
                        newPicture.State = true;
                        newPicture.Path = tmpId + ".png";
                        m_model.PicOfAlbums.InsertOnSubmit(newPicture);
                        m_model.SubmitChanges();
                    }
                    // Returns json

                    return Content("{\"Status\":\"" + "true" + "\",\"Message\":\"" + "Your File Sent Sucessfully" + "\",\"Id\":\"" + r[0].Id + "\",\"Name\":\"" + r[0].Name + "\",\"Size\":\"" + r[0].Length + "\",\"Type\":\"" + r[0].Type + "\"}", "application/json");
                }
                else
                {
                    return Content("{\"Status\":\"" + "false" + "\",\"Message\":\"" + "User not found" + "\"}", "application/json");
                }
            }
            catch (Exception ex)
            {
                return Content("{\"Status\":\"" + "false" + "\",\"Message\":\"" + ex.Message + "\"}", "application/json");
            }
        }
Пример #2
0
 partial void UpdatePicOfAlbum(PicOfAlbum instance);
Пример #3
0
 partial void DeletePicOfAlbum(PicOfAlbum instance);
Пример #4
0
 partial void InsertPicOfAlbum(PicOfAlbum instance);