Ejemplo n.º 1
0
        //public ActionResult Edit([Bind(Include = "MasterPartFId,CustomerId,CustomerDivisionId,MlsDivisionId,ActivePartId,PartTypeId,DocStatusId,CustomerPn,MlsPn,PartDescription,Weight,HtsCode,Notes")] MasterPartF masterPartF)
        public ActionResult Edit(MasterPartF masterPartF)
        {
            if (ModelState.IsValid)
            {
                //New Files
                for (int i = 0; i < Request.Files.Count; i++)
                {
                    var file = Request.Files[i];

                    if (file != null && file.ContentLength > 0)
                    {
                        var             fileName        = Path.GetFileName(file.FileName);
                        FileMasterPartF fileMasterPartF = new FileMasterPartF()
                        {
                            FileName      = fileName,
                            Extension     = Path.GetExtension(fileName),
                            Id            = Guid.NewGuid(),
                            MasterPartFId = masterPartF.MasterPartFId
                        };
                        var path = Path.Combine(Server.MapPath("~/images/"), fileMasterPartF.Id + fileMasterPartF.Extension);
                        file.SaveAs(path);

                        db.Entry(fileMasterPartF).State = EntityState.Added;
                    }
                }

                db.Entry(masterPartF).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View());
            //return View(masterPartF);
        }
Ejemplo n.º 2
0
        public JsonResult DeleteFile(string id)
        {
            if (String.IsNullOrEmpty(id))
            {
                Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return(Json(new { Result = "Error" }));
            }
            try
            {
                Guid            guid            = new Guid(id);
                FileMasterPartF fileMasterPartF = db.FileMasterPartFs.Find(guid);
                if (fileMasterPartF == null)
                {
                    Response.StatusCode = (int)HttpStatusCode.NotFound;
                    return(Json(new { Result = "Error" }));
                }

                //Remove from database
                db.FileMasterPartFs.Remove(fileMasterPartF);
                db.SaveChanges();

                //Delete file from the file system
                var path = Path.Combine(Server.MapPath("~/images/"), fileMasterPartF.Id + fileMasterPartF.Extension);
                if (System.IO.File.Exists(path))
                {
                    System.IO.File.Delete(path);
                }
                return(Json(new { Result = "OK" }));
            }
            catch (Exception ex)
            {
                return(Json(new { Result = "ERROR", Message = ex.Message }));
            }
        }
Ejemplo n.º 3
0
        //public ActionResult Create([Bind(Include = "MasterPartFId,CustomerId,CustomerDivisionId,MlsDivisionId,ActivePartId,PartTypeId,DocStatusId,CustomerPn,MlsPn,PartDescription,Weight,HtsCode,Notes")] MasterPartF masterPartF)
        public ActionResult Create(MasterPartF masterPartF)
        {
            if (ModelState.IsValid)
            {
                List <FileMasterPartF> fileMasterPartFs = new List <FileMasterPartF>();
                for (int i = 0; i < Request.Files.Count; i++)
                {
                    var file = Request.Files[i];

                    if (file != null && file.ContentLength > 0)
                    {
                        var             fileName        = Path.GetFileName(file.FileName);
                        FileMasterPartF fileMasterPartF = new FileMasterPartF()
                        {
                            FileName  = fileName,
                            Extension = Path.GetExtension(fileName),
                            Id        = Guid.NewGuid()
                        };
                        fileMasterPartFs.Add(fileMasterPartF);

                        var path = Path.Combine(Server.MapPath("~/images/"), fileMasterPartF.Id + fileMasterPartF.Extension);
                        file.SaveAs(path);
                    }
                }

                masterPartF.FileMasterPartFs = fileMasterPartFs;
                db.MasterPartFs.Add(masterPartF);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View());
            //return View(masterPartF);
        }