Пример #1
0
        public JsonResult Delete(int id)
        {
            try
            {
                MasterPartF masterPartF = db.MasterPartFs.Find(id);
                if (masterPartF == null)
                {
                    Response.StatusCode = (int)HttpStatusCode.NotFound;
                    return(Json(new { Result = "Error" }));
                }

                //delete files from the file system

                foreach (var item in masterPartF.FileMasterPartFs)
                {
                    String path = Path.Combine(Server.MapPath("~/images/"), item.Id + item.Extension);
                    if (System.IO.File.Exists(path))
                    {
                        System.IO.File.Delete(path);
                    }
                }

                db.MasterPartFs.Remove(masterPartF);
                db.SaveChanges();
                return(Json(new { Result = "OK" }));
            }
            catch (Exception ex)
            {
                return(Json(new { Result = "ERROR", Message = ex.Message }));
            }
        }
Пример #2
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);
        }
Пример #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);
        }
Пример #4
0
        // GET: MasterPartFs/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            MasterPartF masterPartF = db.MasterPartFs.Find(id);

            if (masterPartF == null)
            {
                return(HttpNotFound());
            }
            return(View(masterPartF));
        }
Пример #5
0
        // GET: MasterPartFs/Edit/5
        public ActionResult Edit(int?id)
        {
            var masterparts = db.MasterPartFs.SingleOrDefault(c => c.MasterPartFId == id);

            ViewBag.ReturnUrl = Request.UrlReferrer;
            var customers         = db.Customers.ToList();
            var customerdivisions = db.CustomerDivisions.ToList();
            var mlsdivisions      = db.MlsDivisions.ToList();
            var parttypes         = db.PartTypes.ToList();
            var activeparts       = db.ActiveParts.ToList();
            var statuses          = db.DocStatuses.ToList();

            var viewModel = new SaveMasterPartFViewModel()
            {
                MasterPartF       = masterparts,
                Customers         = customers,
                CustomerDivisions = customerdivisions,
                MlsDivisions      = mlsdivisions,
                PartTypes         = parttypes,
                ActiveParts       = activeparts,
                DocStatuses       = statuses
            };

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            MasterPartF masterPartF = db.MasterPartFs.Include(s => s.FileMasterPartFs).SingleOrDefault(x => x.MasterPartFId == id);

            //MasterPartF masterPartF = db.MasterPartFs.Find(id);
            if (masterPartF == null)
            {
                return(HttpNotFound());
            }
            return(View("Edit", viewModel));
            //return View(masterPartF);
        }