Ejemplo n.º 1
0
        public ActionResult Create([Bind(Include = "Id,File_Id,Name,Description,Notes,CreateDate,UpdateDate")] Models.Type type)
        {
            if (ModelState.IsValid)
            {
                type.CreateDate = new SqlDateTime(DateTime.Now).Value;
                db.Type.Add(type);
                db.SaveChanges();
                return(RedirectToAction("Details", new { id = type.Id }));
            }

            return(View(type));
        }
Ejemplo n.º 2
0
        public ActionResult Create([Bind(Include = "Id,File_Id,Name,Description,Notes,CreateDate,UpdateDate")] Location location)
        {
            if (ModelState.IsValid)
            {
                location.CreateDate = new SqlDateTime(DateTime.Now).Value;
                db.Location.Add(location);
                db.SaveChanges();
                return(RedirectToAction("Details", new { id = location.Id }));
            }

            return(View(location));
        }
Ejemplo n.º 3
0
        public ActionResult Create([Bind(Include = "Id,Full_Name,Address,Email,Website,Name,Description,Notes,CreateDate,UpdateDate")] Manufacturer manufacturer)
        {
            if (ModelState.IsValid)
            {
                manufacturer.CreateDate = new SqlDateTime(DateTime.Now).Value;
                db.Manufacturer.Add(manufacturer);
                db.SaveChanges();
                return(RedirectToAction("Details", new { id = manufacturer.Id }));
            }

            return(View(manufacturer));
        }
Ejemplo n.º 4
0
        public ActionResult Create([Bind(Include = "Id,Number,Keywords,Voltage,Current,Quantity,Pin_Count,Price,Name,Description,Notes,Manufacturer_Id,Location_Id,Package_Id,Type_Id")] Part part)
        {
            if (ModelState.IsValid)
            {
                part.CreateDate = new SqlDateTime(DateTime.Now).Value;

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

            return(View(part));
        }
Ejemplo n.º 5
0
        public Models.File PrepareFile(HttpPostedFileBase file)
        {
            string _FileName    = Path.GetFileName(file.FileName);
            string _path        = Path.Combine(HttpContext.Current.Server.MapPath("~/Content/Files/Static"), DateTime.Now.ToString("yyMMddHHmmss") + "_" + _FileName);
            string relativePath = "~/Content/Files/Static/" + DateTime.Now.ToString("yyMMddHHmmss") + "_" + _FileName;
            var    dbFile       = new Models.File()
            {
                Name       = _FileName,
                File_Path  = _path,
                CreateDate = DateTime.Now
            };

            file.SaveAs(_path);
            db.File.Add(dbFile);
            db.SaveChanges();

            return(dbFile);
        }
Ejemplo n.º 6
0
 public ActionResult UploadFile(HttpPostedFileBase file, long id, string sender = "", string file_type = "")
 {
     try
     {
         if (file.ContentLength > 0)
         {
             string _FileName    = Path.GetFileName(file.FileName);
             string _path        = Path.Combine(Server.MapPath("~/Content/Files/" + file_type), DateTime.Now.ToString("yyMMddHHmmss") + "_" + _FileName);
             string relativePath = "~/Content/Files/" + file_type + "/" + DateTime.Now.ToString("yyMMddHHmmss") + "_" + _FileName;
             file.SaveAs(_path);
             if (sender.Equals(Constants.FILE_SENDER_PART))
             {
                 var part = db.Part.Find(id);
                 if (part != null)
                 {
                     part.Files.Add(new Models.File()
                     {
                         Name       = _FileName,
                         File_Path  = relativePath,
                         File_Type  = file_type,
                         CreateDate = DateTime.Now
                     });
                     db.SaveChanges();
                 }
             }
             if (sender.Equals(Constants.FILE_SENDER_MAN))
             {
                 var db    = new EMBContext();
                 var manuf = db.Manufacturer.Find(id);
                 if (manuf != null)
                 {
                     manuf.File = new Models.File()
                     {
                         Name       = _FileName,
                         File_Path  = relativePath,
                         File_Type  = file_type,
                         CreateDate = DateTime.Now
                     };
                     db.SaveChanges();
                 }
             }
             if (sender.Equals(Constants.FILE_SENDER_LOC))
             {
                 var db   = new EMBContext();
                 var item = db.Location.Find(id);
                 if (item != null)
                 {
                     item.File = new Models.File()
                     {
                         Name       = _FileName,
                         File_Path  = relativePath,
                         File_Type  = file_type,
                         CreateDate = DateTime.Now
                     };
                     db.SaveChanges();
                 }
             }
             if (sender.Equals(Constants.FILE_SENDER_PCK))
             {
                 var db   = new EMBContext();
                 var item = db.Package.Find(id);
                 if (item != null)
                 {
                     item.File = new Models.File()
                     {
                         Name       = _FileName,
                         File_Path  = relativePath,
                         File_Type  = file_type,
                         CreateDate = DateTime.Now
                     };
                     db.SaveChanges();
                 }
             }
             if (sender.Equals(Constants.FILE_SENDER_TYP))
             {
                 var db   = new EMBContext();
                 var item = db.Type.Find(id);
                 if (item != null)
                 {
                     item.File = new Models.File()
                     {
                         Name       = _FileName,
                         File_Path  = relativePath,
                         File_Type  = file_type,
                         CreateDate = DateTime.Now
                     };
                     db.SaveChanges();
                 }
             }
         }
         ViewBag.Message = "File Uploaded Successfully!!";
         return(RedirectToAction("Details", sender, new { id = id }));
     }
     catch
     {
         ViewBag.Message = "File upload failed!!";
         return(RedirectToAction("Details", sender, new { id = id }));
     }
 }