Пример #1
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);
                FileQALog fileQALog = db.FileQALogs.Find(guid);
                if (fileQALog == null)
                {
                    Response.StatusCode = (int)HttpStatusCode.NotFound;
                    return(Json(new { Result = "Error" }));
                }

                //Remove from database
                db.FileQALogs.Remove(fileQALog);
                db.SaveChanges();

                //Delete file from the file system
                var path = Path.Combine(Server.MapPath("~/images/"), fileQALog.Id + fileQALog.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 }));
            }
        }
Пример #2
0
        //public ActionResult Create([Bind(Include = "QALogId,QACreated,QANo,QATypeId,PartTypeId,MlsDivisionId,CustomerId,CustomerDivisionId,ProblemFoundId,CustomerPn,ProblemDescription,ContainmentChina,CleanPointChina,ContainmentUSA,CleanPointUsa,NCRNo,CQStatusId,CARNo,SupplierId,CustomerCARNo,MLSChampion,SupplierChampion,Notes")] QALog qALog)
        public ActionResult Create(QALog qALog, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                List <FileQALog> fileQALogs = new List <FileQALog>();
                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);
                        FileQALog fileQALog = new FileQALog()
                        {
                            FileName  = fileName,
                            Extension = Path.GetExtension(fileName),
                            Id        = Guid.NewGuid()
                        };
                        fileQALogs.Add(fileQALog);

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

                qALog.FileQALogs = fileQALogs;
                db.QALogs.Add(qALog);
                db.SaveChanges();
                return(Redirect(returnUrl));
                //return RedirectToAction("Index");
            }

            //return View(qALog);
            return(View());
        }
Пример #3
0
        //public ActionResult Edit([Bind(Include = "QALogId,QACreated,QANo,QATypeId,PartTypeId,MlsDivisionId,CustomerId,CustomerDivisionId,ProblemFoundId,CustomerPn,ProblemDescription,ContainmentChina,CleanPointChina,ContainmentUSA,CleanPointUsa,NCRNo,CQStatusId,CARNo,SupplierId,CustomerCARNo,MLSChampion,SupplierChampion,Notes")] QALog qALog)
        public ActionResult Edit(QALog qALog, string returnUrl)
        {
            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);
                        FileQALog fileQALog = new FileQALog()
                        {
                            FileName  = fileName,
                            Extension = Path.GetExtension(fileName),
                            Id        = Guid.NewGuid(),
                            QALogId   = qALog.QALogId
                        };
                        var path = Path.Combine(Server.MapPath("~/images/"), fileQALog.Id + fileQALog.Extension);
                        file.SaveAs(path);

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

                db.Entry(qALog).State = EntityState.Modified;
                db.SaveChanges();
                return(Redirect(returnUrl));
                //return RedirectToAction("Index");
            }
            return(View());
            //return View(qALog);
        }