예제 #1
0
        public ActionResult Edit([Bind(Include = "Id,File_Id,Name,Description,Notes,CreateDate,UpdateDate,del_file")] Models.Type type)
        {
            if (ModelState.IsValid)
            {
                db.Entry(type).State = EntityState.Modified;
                type.UpdateDate      = new SqlDateTime(DateTime.Now).Value;

                var checkbox = ValueProvider.GetValue("del_file");
                if (checkbox != null)
                {
                    var fid  = Int32.Parse(checkbox.AttemptedValue.Replace('/', '\0'));
                    var file = db.File.Find(fid);

                    if (System.IO.File.Exists(Server.MapPath(file.File_Path)))
                    {
                        System.IO.File.Delete(Server.MapPath(file.File_Path));
                        db.Type.Find(type.Id).File = null;
                        type.File_Id = null;
                        db.File.Remove(file);
                    }
                }

                db.SaveChanges();
                return(RedirectToAction("Details", new { id = type.Id }));
            }
            return(View(type));
        }
예제 #2
0
        public ActionResult Edit([Bind(Include = "Id,Number,Keywords,Voltage,Current,Quantity,Pin_Count,Price,Name,Description,Notes,CreateDate,Manufacturer_Id,Location_Id,Package_Id,Type_Id,del_file")] Part part)
        {
            if (ModelState.IsValid)
            {
                db.Entry(part).State = EntityState.Modified;

                part.UpdateDate = new SqlDateTime(DateTime.Now).Value;
                var checkboxes = ValueProvider.GetValue("del_file");
                if (checkboxes != null)
                {
                    var files = checkboxes.AttemptedValue.Replace('/', '\0').Split(',').Select(a => long.Parse(a)).ToList();

                    foreach (var file in db.File.Where(a => files.Contains(a.Id)))
                    {
                        if (System.IO.File.Exists(Server.MapPath(file.File_Path)))
                        {
                            System.IO.File.Delete(Server.MapPath(file.File_Path));
                            db.File.Remove(file);
                        }
                    }
                }

                db.SaveChanges();
                return(RedirectToAction("Details", new { id = part.Id }));
            }
            return(View(part));
        }