Exemplo n.º 1
0
        public ActionResult Create([Bind(Exclude = "DocumentID")] Document newDoc, HttpPostedFileBase file)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            try
            {
                //Save file to server if user selected a file
                if (file != null && file.ContentLength > 0)
                {
                    newDoc.FileName = Path.GetFileName(file.FileName);
                    newDoc.MimeType = file.ContentType;
                    var path = Path.Combine(basePath, newDoc.FileName);
                    file.SaveAs(path);
                }

                newDoc.DeveloperID = _dataModel.Developers.Single(d => d.UserName == User.Identity.Name).DeveloperID;
                newDoc.Name        = newDoc.Name;
                newDoc.EntryDate   = DateTime.Now;
                _dataModel.AddToDocuments(newDoc);
                _dataModel.SaveChanges();

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(RedirectToAction("Index"));
            }
        }