Ejemplo n.º 1
0
        public ActionResult Edit(FishPiCalculation p)
        {
            //Not writing to DB- why??
            if (ModelState.IsValid)
            {
                DisplayCalculation.UpdateCalculation(p);
                return(RedirectToAction("Index", "Manage"));
            }
            else
            {
                ModelState.AddModelError("MessageError", "Your changes were not saved");
            }

            return(View(p));
        }
Ejemplo n.º 2
0
        public ActionResult Edit(int?id)
        {
            //redirect
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.NotFound));
            }

            FishPiCalculation p = DisplayCalculation.GetCalcById(id.Value);

            if (p == null)
            {
                return(HttpNotFound());
            }

            return(View(p));
        }
Ejemplo n.º 3
0
        public ActionResult FishPiCalculation(FishPiCalculation p, HttpPostedFileBase textFile)
        {
            string extension = @"C:\Users\Sam\Documents\Test.txt";             //ask Joe if this is right- how do I get the file I uploaded?
            string e         = Path.GetExtension(extension);

            //checks to make sure a file is being uploaded
            if (textFile == null)
            {
                ModelState.AddModelError("FileURL", "Please upload a .txt file");
            }

            //validates file type
            if (e != ".txt")
            {
                ModelState.AddModelError("FileURL", "Please upload a .txt file");
            }

            if (ModelState.IsValid)
            {
                if (textFile != null &&
                    textFile.ContentLength > 0)
                {
                    string fileName =
                        Guid.NewGuid().ToString() +
                        Path.GetExtension(textFile.FileName);

                    //generate a path with the file name appended
                    string path = Path.Combine(
                        Server.MapPath("~/Files"),
                        fileName);

                    textFile.SaveAs(path);
                    p.FilePath = fileName;
                }

                DisplayCalculation.AddCalculation(p);
                return(RedirectToAction("FishPiCalculation", "PiCalculator"));
            }
            return(View(p));
        }
Ejemplo n.º 4
0
        public ActionResult FishPiCalculation(FishPiCalculation p, HttpPostedFileBase textFile)
        {
            //checks to make sure a file is being uploaded
            //validates file type
            if (textFile == null)
            {
                ModelState.AddModelError("MessageError", "Please upload a .txt file");
            }
            else
            {
                string e = Path.GetExtension(textFile.FileName);
                if (e != ".txt")
                {
                    ModelState.AddModelError("MessageError", "Please upload a .txt file");
                }
            }

            //adds path of file to DB
            ModelState.Remove("Title");
            if (ModelState.IsValid)
            {
                if (textFile != null && textFile.ContentLength > 0)
                {
                    p.Title = Path.GetFileName(textFile.FileName);
                    string fileName = Guid.NewGuid().ToString() + Path.GetExtension(textFile.FileName);

                    //generate a path with the file name appended
                    string path = Path.Combine(Server.MapPath("~/Files"), fileName);

                    textFile.SaveAs(path);
                    p.FilePath = fileName;
                    DisplayCalculation.AddCalculation(p);
                    return(RedirectToAction("FishPiCalculation", "PiCalculator"));
                }
            }
            return(View(p));
        }