Exemplo n.º 1
0
        private ActionResult UploadFile(Submission submission)
        {
            if (Request.Files.Count == 0)
                return RedirectToAction("Index");

            var postedFile = Request.Files[0];

            if (postedFile == null)
                return RedirectToAction("Index");

            if (postedFile.FileName.Length < 4)
                return RedirectToAction("Index");

            var extension = postedFile.FileName.Substring(postedFile.FileName.Length - 4, 4);

            if (!extension.Equals(".zip"))
                TempData["Message"] = "Formato do arquivo diferente de .zip";
            else if (postedFile.ContentLength / 1024 > 10240)
                TempData["Message"] = "Tamanho máximo permitido: 10Mb";
            else
            {
                var fileName = string.Concat(Guid.NewGuid(), ".zip");
                var filePath = string.Concat(Server.MapPath("~/Uploads/"), fileName);

                postedFile.SaveAs(filePath);

                submission.FilePath = fileName;
                submission.ModifiedOn = DateTime.Now;

                using (var partialdb = new DevdayEntities())
                {
                    partialdb.Submissions.Attach(submission);
                    partialdb.Entry(submission).Property(e => e.FilePath).IsModified = true;
                    partialdb.Entry(submission).Property(e => e.ModifiedOn).IsModified = true;
                    partialdb.SaveChanges();
                }
            }

            return RedirectToAction("Index");
        }
Exemplo n.º 2
0
        public ActionResult Edit(Submission submission)
        {
            if (_dataLimiteSubmissaoExcedido)
            {
                TempData["message"] = "Data limite de submissão excedido";
                return RedirectToAction("Index");
            }

            var userID = ((CustomPrincipal)HttpContext.User).UserID;
            var submissionCheck = _db.Submissions.FirstOrDefault(t => t.UserID == userID &&
                                                                      t.ID == submission.ID);
            if (submissionCheck == null)
                return RedirectToAction("Index");

            submission.UserID = userID;
            submission.ModifiedOn = DateTime.Now;

            if (ModelState.IsValid)
            {
                using (var partialdb = new DevdayEntities())
                {
                    partialdb.Submissions.Attach(submission);
                    partialdb.Entry(submission).Property(e => e.Name).IsModified = true;
                    partialdb.Entry(submission).Property(e => e.Description).IsModified = true;
                    partialdb.Entry(submission).Property(e => e.ModifiedOn).IsModified = true;
                    partialdb.SaveChanges();
                }
                return Request.Files.Count == 0 ? RedirectToAction("Index") : UploadFile(submission);
            }

            return View(submission);
        }