示例#1
0
        public ActionResult Upload(Guid id, HttpPostedFileBase[] files)
        {
            try
            {
                EstimatorModel estimatorModel = db.EstimatorModels.Find(id);

                // Giving new name and saving to disk
                foreach (HttpPostedFileBase file in files)
                {
                    //Checking file is available to save.
                    if (file != null)
                    {
                        file.SaveAs(Path.Combine(Server.MapPath(estimatorModel.Directory), file.FileName));
                    }
                }

                // Returning JSON
                return(Json(new
                {
                    success = true,
                    response = "File uploaded"
                }));
            }
            catch (Exception exception)
            {
                return(Json(new
                {
                    success = false,
                    response = exception.Message
                }));
            }
        }
示例#2
0
 public ActionResult Edit([Bind(Include = "EstimatorModelID,Name,Directory,PythonFile,Active,DateTime")] EstimatorModel estimatorModel)
 {
     if (ModelState.IsValid)
     {
         db.Entry(estimatorModel).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(estimatorModel));
 }
示例#3
0
        // GET: EstimatorModels/Deactivate/5
        public ActionResult Deactivate(Guid id)
        {
            EstimatorModel estimatorModel = db.EstimatorModels.Find(id);

            estimatorModel.Active = false;

            db.Entry(estimatorModel).State = EntityState.Modified;
            db.SaveChanges();

            return(RedirectToAction("Index"));
        }
示例#4
0
        // GET: EstimatorModels/Edit/5
        public ActionResult Edit(Guid?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            EstimatorModel estimatorModel = db.EstimatorModels.Find(id);

            if (estimatorModel == null)
            {
                return(HttpNotFound());
            }
            return(View(estimatorModel));
        }
示例#5
0
        public ActionResult Create([Bind(Include = "EstimatorModelID,Name,Directory,PythonFile,Active,DateTime")] EstimatorModel estimatorModel)
        {
            if (ModelState.IsValid)
            {
                estimatorModel.EstimatorModelID = Guid.NewGuid();
                estimatorModel.DateTime         = DateTime.Now;
                estimatorModel.Directory        = "~/Estimator/" + estimatorModel.Name.Replace(' ', '_') + "-" + Guid.NewGuid();
                estimatorModel.Active           = false;

                Directory.CreateDirectory(Server.MapPath(estimatorModel.Directory));

                db.EstimatorModels.Add(estimatorModel);
                db.SaveChanges();
                return(RedirectToAction("Upload", new { id = estimatorModel.EstimatorModelID }));
            }

            return(View(estimatorModel));
        }
示例#6
0
        // GET: EstimatorModels/Activate/5
        public ActionResult Activate(Guid id)
        {
            foreach (var Estimator in db.EstimatorModels.Where(e => e.Active == true))
            {
                Estimator.Active          = false;
                db.Entry(Estimator).State = EntityState.Modified;
            }
            db.SaveChanges();

            EstimatorModel estimatorModel = db.EstimatorModels.Find(id);

            estimatorModel.Active = true;

            db.Entry(estimatorModel).State = EntityState.Modified;
            db.SaveChanges();

            return(RedirectToAction("Index"));
        }
示例#7
0
        public ActionResult DeleteConfirmed(Guid id)
        {
            EstimatorModel estimatorModel = db.EstimatorModels.Find(id);

            System.IO.DirectoryInfo di = new DirectoryInfo(Server.MapPath(estimatorModel.Directory));

            foreach (FileInfo file in di.GetFiles())
            {
                file.Delete();
            }
            foreach (DirectoryInfo dir in di.GetDirectories())
            {
                dir.Delete(true);
            }

            if (Directory.Exists(Server.MapPath(estimatorModel.Directory)))
            {
                Directory.Delete(Server.MapPath(estimatorModel.Directory));
            }

            db.EstimatorModels.Remove(estimatorModel);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }