Ejemplo n.º 1
0
        public JsonResult UploadFile(List <IFormFile> files)
        {
            string name     = Guid.NewGuid().ToString("n");
            string filePath = _hostingEnvironment.WebRootPath + @"/UploadFiles/";

            foreach (var formFile in files)
            {
                string ext = System.IO.Path.GetExtension(formFile.FileName);
                System.IO.Directory.CreateDirectory(filePath);
                if (formFile.Length > 0)
                {
                    string path = filePath + name + ext;
                    using (var stream = new FileStream(path, FileMode.Create))
                    {
                        formFile.CopyToAsync(stream);

                        DtFile entity = new DtFile();
                        entity.FileExt = ext;
                        entity.Length  = (Int32)formFile.Length;
                        entity.NewName = name;
                        entity.OldName = formFile.FileName;
                        entity.Path    = @"/UploadFiles/" + name + ext;
                        entity.Type    = 4;
                        var extlist = FIleTypeServer.GetFileTypeList();
                        foreach (var item in extlist)
                        {
                            if (item.ExtList.Contains(ext.ToLower()))
                            {
                                entity.Type = item.Type;
                                break;
                            }
                        }

                        _fileMgmt.Inserter(entity);
                        _fileMgmt.Save();
                    }
                }
            }

            return(Json(new { flag = true }));
        }
Ejemplo n.º 2
0
        public ActionResult Edit(AccountModel model)
        {
            var entity = _account.GetById(model.Id);

            if (entity == null)
            {
                int exsitCount = _account.Quyer()
                                 .Where(s => s.LoginName == model.LoginName.Trim() || s.Name == model.Name.Trim())
                                 .Count();
                if (exsitCount > 0)
                {
                    ModelState.AddModelError("", "登录名或用户已存在");
                    return(View(model));
                }

                entity          = new Account();
                entity.Password = "******";
                _account.Inserter(entity);
            }

            entity.Age       = model.Age;
            entity.Name      = model.Name;
            entity.Remark    = model.Remark;
            entity.LoginName = model.LoginName;

            _account.Save();

            var list = _account.Quyer().ToList().Select(s => {
                var m    = new AccountModel();
                m.Id     = s.Id;
                m.Age    = s.Age;
                m.Name   = s.Name;
                m.Remark = s.Remark;
                return(m);
            }).ToList();

            var cacheEntryOptions = new MemoryCacheEntryOptions()
                                    // Keep in cache for this time, reset time if accessed.
                                    .SetSlidingExpiration(TimeSpan.FromDays(3));

            _cache.Remove("userlist");
            _cache.Set("userlist", list, cacheEntryOptions);

            return(RedirectToAction("list"));
        }