Exemplo n.º 1
0
        public virtual ActionResult Create(XZKFYDCFInfo item)
        {
            if (ModelState.IsValid)
            {
                _db.XZKFYDCFs.Add(item);
                _db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View());
        }
        public virtual ActionResult Create(StudentInfo student)
        {
            if (ModelState.IsValid)
            {
                _db.Students.Add(student);
                _db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View());
        }
        public virtual ActionResult Create(RoleInfo role)
        {
            if (ModelState.IsValid)
            {
                _db.Roles.Add(role);
                _db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View());
        }
        public virtual ActionResult Create(UserInfo user)
        {
            if (ModelState.IsValid)
            {
                user.Password = UtilityHelper.MD5(user.Password);
                _db.Users.Add(user);
                _db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View());
        }
Exemplo n.º 5
0
        public virtual ActionResult Create(BADLInfo item)
        {
            if (ModelState.IsValid)
            {
                item.总分 = GetSum(item);
                _db.BADLs.Add(item);
                _db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View());
        }
Exemplo n.º 6
0
        public static UploadedFileInfo Upload(HttpPostedFileBase fileData, string targetDirectory)
        {
            var uploadedFileRootDirectory = "UploadedFiles";

            if (fileData != null)
            {
                try
                {
                    var targetSaveDirectory =
                        HttpContext.Current.Server.MapPath($"~/{uploadedFileRootDirectory}/{targetDirectory}");

                    if (!Directory.Exists(targetSaveDirectory))
                    {
                        Directory.CreateDirectory(targetSaveDirectory);
                    }

                    var sourceFileName = fileData.FileName;
                    var fileExtension  = Path.GetExtension(sourceFileName);
                    var guid           = Guid.NewGuid().ToString();
                    var baseDirectory  = $"{uploadedFileRootDirectory}/{targetDirectory}";
                    var saveFileName   = $"{guid}{fileExtension}";
                    var saveFilePath   = $"{targetSaveDirectory}\\{saveFileName}";

                    fileData.SaveAs(saveFilePath);

                    var file = new UploadedFileInfo
                    {
                        FileExtension = fileExtension,
                        Guid          = guid,
                        FileName      = saveFileName,
                        BaseDirectory = baseDirectory,
                        UploadTime    = DateTime.Now
                    };

                    var db = new SchooldDbContext();
                    db.UploadFiles.Add(file);
                    db.SaveChanges();

                    return(file);
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message);
                }
            }
            return(null);
        }