Exemplo n.º 1
0
        public void AddFile(FileModel file)
        {
            var f = from ff in context.FileModels
                    where ff.ProductID == file.ProductID
                    select ff;
            if (f.Count() > 0)
            {
                // ograniczenie do tylko jednego pliku
                var ph = context.FileModels.Single(x => x.ProductID == file.ProductID);
                ph.Name = file.Name;
                ph.ContentType = file.ContentType;
                ph.ProductID = file.ProductID;
                ph.Data = file.Data;
            }
            else
            {
                FileModel fm = new FileModel();
                fm.Name = file.Name;
                fm.ContentType = file.ContentType;
                fm.ProductID = file.ProductID;
                fm.Data = file.Data;
                context.FileModels.InsertOnSubmit(fm);
            }

            context.SubmitChanges();
        }
Exemplo n.º 2
0
 //
 // GET: /Product/SetImage/5
 public ActionResult SetImage(int id)
 {
     if (files.ValidateProductID(id))
     {
         FileModel file = new FileModel();
         file.ProductID = id;
         return View(file);
     }
     return RedirectToAction("Index", "Category");
 }
Exemplo n.º 3
0
        public ActionResult SetImage(int id, FileModel photo)
        {
            try
            {
                photo.ProductID = id;

                if (Request.IsAjaxRequest())
                {
                    photo.Data = Request.BinaryRead(Request.ContentLength);
                    photo.Name = Request.Headers.Get("X-File-Name");
                    photo.ContentType = Request.ContentType;

                    string error = photo.Validate;
                    if (error == null)
                    {
                        files.AddFile(photo);
                        return Json(new { success = true });
                    }

                    return Json(new { errors = error });
                }
                else
                {
                    if (ModelState.IsValid)
                    {
                        photo.Name = photo.file.FileName;
                        photo.ContentType = photo.file.ContentType;
                        byte[] tmp = new byte[photo.file.ContentLength];
                        photo.file.InputStream.Read(tmp, 0, photo.file.ContentLength);
                        photo.Data = tmp;

                        files.AddFile(photo);
                        return RedirectToAction("Details", "Product", new { id = id });
                    }

                    return View(photo);
                }
            }
            catch (Exception e)
            {
                if (Request.IsAjaxRequest())
                {
                    return Json(new { success = false, error = e.Message });
                }
                else
                {
                    ViewData["ERROR"] = e.Message;
                    return View();
                }
            }
        }
Exemplo n.º 4
0
		private void detach_FileModels(FileModel entity)
		{
			this.SendPropertyChanging();
			entity.ProductModel = null;
		}
Exemplo n.º 5
0
 partial void DeleteFileModel(FileModel instance);
Exemplo n.º 6
0
 partial void UpdateFileModel(FileModel instance);
Exemplo n.º 7
0
 partial void InsertFileModel(FileModel instance);