public PictureItemNoBufferData(PictureItem picture)
 {
     Artist = picture.Artist;
     Created = picture.Created;
     ID = picture.ID;
     Media = picture.Media;
     Price = picture.Price;
     Size = picture.Size;
     Theme = picture.Theme;
     Title = picture.Title;
     UserId = picture.UserId;
     DisplayOrder = picture.DisplayOrder;
 }
Beispiel #2
0
        public void ProcessRequest(HttpContext context)
        {
            try
            {
                HttpPostedFile hpf = context.Request.Files["file"];
               // if (hpf.ContentLength > 0 && FileIsPicture(hpf))
                if (hpf.ContentLength > 0)
                {

                    int chunk = context.Request["chunk"] != null ? int.Parse(context.Request["chunk"]) : 0;
                    int totalChunks = context.Request["chunks"] != null ? int.Parse(context.Request["chunks"]) : 1;

                    string fileName = context.Request["name"] ?? string.Empty;

                    string filePath = context.Server.MapPath("MyFiles");

                    using (var fs = new FileStream(Path.Combine(filePath, fileName), chunk == 0 ? FileMode.Create : FileMode.Append))
                    {
                        var buffer = new byte[hpf.InputStream.Length];
                        hpf.InputStream.Read(buffer, 0, buffer.Length);
                        fs.Write(buffer, 0, buffer.Length);
                    }

                    //only do this part when chunk complete
                    if (chunk == totalChunks-1)
                    {
                        byte[] bufferFinal = ImageProcessor.ImageAsByteArray(Path.Combine(filePath, fileName),
                                                                             System.Drawing.Imaging.ImageFormat.Jpeg);

                        using (ArtGalleryDBContext db = new ArtGalleryDBContext())
                        {
                            var currentUser =  UserDal.AllUsers.FirstOrDefault(x => x.UserName.ToLower() == context.User.Identity.Name.ToLower());
                            if (currentUser == null)
                            {
                                currentUser = new LogOnModel()
                                {
                                    UserId = 99999,
                                    UserName = context.User.Identity.Name
                                };
                                Logger.Info("user could not be found for upload", null);
                            }
                            var picture = new PictureItem
                                                      {
                                                          ImageT = bufferFinal,
                                                          Created = DateTime.Now,
                                                          Artist = currentUser.UserName,
                                                          UserId = currentUser.UserId
                                                      };

                            IPictureDal pictureDal = new PictureDal(db);
                            //saveto db
                            pictureDal.Enitities.Add(picture);
                            pictureDal.SaveChanges();

                        }

                    }

                }
                //save any old file to myFiles...
                //else
                //{
                //    string filePath = context.Server.MapPath("MyFiles") + "\\" +
                //                        System.IO.Path.GetFileName(hpf.FileName);

                //    hpf.SaveAs(filePath);
                //}

                context.Response.Write("1");
            }
            catch (Exception ex)
            {
                Logger.Error("In upload.ashx", ex);
            }
        }
        public ActionResult Create(PictureItem pictureitem)
        {
            if (ModelState.IsValid)
            {
                _pictureDal.Enitities.Add(pictureitem);
                _pictureDal.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(pictureitem);
        }