示例#1
0
        public bool DeleteCategories(Category category)
        {
            var context = new APPContext();

            context.Entry(category).State = System.Data.Entity.EntityState.Deleted;
            return(context.SaveChanges() > 0);
        }
示例#2
0
        public bool SaveCategories(Category category)
        {
            var context = new APPContext();

            context.Categories.Add(category);
            return(context.SaveChanges() > 0);
        }
示例#3
0
        public async Task <IActionResult> UploadToFileSystem(List <IFormFile> files, string description)
        {
            foreach (var file in files)
            {
                var  basePath       = Path.Combine(Directory.GetCurrentDirectory() + "\\Files\\");
                bool basePathExists = System.IO.Directory.Exists(basePath);
                if (!basePathExists)
                {
                    Directory.CreateDirectory(basePath);
                }
                var fileName  = Path.GetFileNameWithoutExtension(file.FileName);
                var filePath  = Path.Combine(basePath, file.FileName);
                var extension = Path.GetExtension(file.FileName);
                if (!System.IO.File.Exists(filePath))
                {
                    using (var stream = new FileStream(filePath, FileMode.Create))
                    {
                        await file.CopyToAsync(stream);
                    }
                    var fileModel = new FileOnFileSystemModel
                    {
                        CreatedOn   = DateTime.UtcNow,
                        FileType    = file.ContentType,
                        Extension   = extension,
                        Name        = fileName,
                        Description = description,
                        FilePath    = filePath
                    };
                    context.FileSOnFileSystemModel.Add(fileModel);
                    context.SaveChanges();
                }
            }

            TempData["Message"] = "File successfully uploaded to File System.";
            return(RedirectToAction("Index"));
        }
示例#4
0
 public void Save()
 {
     _context.SaveChanges();
 }
示例#5
0
 public int Create(UserModel entity)
 {
     _appContext.Users.Add(entity);
     _appContext.SaveChanges();
     return(entity.Id);
 }