Exemplo n.º 1
0
        public ActionResult CreateMilestone(MilestoneViewModel model, HttpPostedFileBase ZipFile, HttpPostedFileBase TxtFile)
        {
            if (ModelState.IsValid)
            {
                ModelState.Clear();
                int MileID = TS.CreateMilestone(model);
                model.ID = MileID;
                if (ZipFile != null)
                {
                    var ZipType  = "zip";
                    var TextType = "txt";

                    var ZipEnding = System.IO.Path.GetExtension(ZipFile.FileName).Substring(1);
                    if (!ZipType.Contains(ZipEnding))
                    {
                        ViewBag.Output  = "Error: upload approriate .zip file";
                        model.UserModel = US.GetUserOverviewByUserName(User.Identity.GetUserName(), model.CourseID);
                        return(View(model));
                    }
                    if (TxtFile != null)
                    {
                        var TextEnding = System.IO.Path.GetExtension(TxtFile.FileName).Substring(1);
                        if (!TextType.Contains(TextEnding))
                        {
                            ViewBag.Output  = "Error: upload approriate .txt file";
                            model.UserModel = US.GetUserOverviewByUserName(User.Identity.GetUserName(), model.CourseID);
                            return(View(model));
                        }
                    }
                    Stopwatch watch = new Stopwatch();
                    watch.Start();

                    try
                    {
                        model = TS.CompileMilestoneUpload(model, ZipFile, TxtFile);
                    }
                    catch
                    {
                        //return error, compile failed, invalid file?
                        throw new Exception();
                    }

                    watch.Stop();
                    TimeSpan ts = watch.Elapsed;
                    ViewBag.Output = "Compiled in " + ts.Seconds + "." + ts.Milliseconds / 10 + " seconds";

                    TS.EditMilestone(model);
                }
            }
            model.UserModel = US.GetUserOverviewByUserName(User.Identity.GetUserName(), model.CourseID);
            return(View(model));
        }