public ActionResult Rename(string id, string name) { try { string path = PathName(id); string newPath = path.Substring(0, path.LastIndexOf("\\") + 1) + name; Directory.Move(path, newPath); if (id.Contains("file") == true) { id = id.Replace("file", ""); directoryContext.Files.First(x => x.FileCode.ToString() == id).Name = name; } else { directoryContext.Folders.First(x => x.FolderCode.ToString() == id).Name = name; } directoryContext.SaveChanges(); return(Json(true)); } catch (Exception e) { return(Json(e.ToString())); } }
public void UploadFiles(Files filesList, long id = 0) { var directory = GetDirectory(id); if (directory == null) { throw new Exception("Directory is Invalid"); } var filesOnServer = directory.File.ToDictionary(r => r.Name); try { foreach (var file in filesList) { if (!filesOnServer.ContainsKey(file.Name)) { directory.File.Add(file); db.Entry(file).State = System.Data.EntityState.Added; } } db.SaveChanges(); } catch (DbUpdateException) { throw; } }
public IActionResult Create([FromBody] DirectoryItem item) { if (item == null) { return(BadRequest()); } _context.DirectoryItems.Add(item); _context.SaveChanges(); return(CreatedAtRoute("GetDirectory", new { id = item.Id }, item)); }
public IActionResult PeopleAdd([FromForm] PersonVM personVM) { Person person = new Person(); if (ModelState.IsValid) { person.Name = personVM.Name; person.Surname = personVM.Surname; person.Company = personVM.Company; _directorycontext.People.Add(person); _directorycontext.SaveChanges(); return(Ok(personVM)); } else { return(BadRequest(ModelState.IsValid)); } }
public IActionResult Add([FromForm] PersonAddVM personAdd) { if (ModelState.IsValid) { Person person = new Person(); person.Name = personAdd.name; person.SurName = personAdd.surName; person.Company = personAdd.company; _directoryContext.People.Add(person); _directoryContext.SaveChanges(); personAdd.id = person.ID; return(Ok(personAdd)); } else { return(BadRequest(ModelState.Values)); } }
public DirectoryController(DirectoryContext context) { _context = context; if (_context.DirectoryItems.Count() == 0) { _context.DirectoryItems.Add(new DirectoryItem { Title = "Item1" }); _context.SaveChanges(); } }
public async Task <bool> CreateUser(UserModel userModel) { if (userModel == null) { throw new ArgumentNullException(); } try { User userEntity = new User() { Id = userModel.Id, Address1 = userModel.Address1, Age = userModel.Age, Birthday = userModel.Birthday, CivilStatus = userModel.CivilStatus, ContactNumber = userModel.ContactNumber, Country = userModel.Country, Department = userModel.Department, FirstName = userModel.FirstName, Gender = userModel.Gender, HireDate = userModel.HireDate, HobbiesAndInterest = userModel.HobbiesAndInterest, LanguagesSpoken = userModel.LanguagesSpoken, LastName = userModel.LastName, Password = userModel.Password, PasswordAttemptFail = userModel.PasswordAttemptFail, State = userModel.State, UserName = userModel.UserName, UserType = userModel.UserType.ToString() }; _context.Users.Add(userEntity); _context.SaveChanges(); return(true); } catch (Exception) { return(false); } }
public static void Initialize(IServiceProvider serviceProvider) { using (var context = new DirectoryContext( serviceProvider.GetRequiredService < DbContextOptions <DirectoryContext> >())) { // Look for any movies. if (context.Person.Any()) { return; // DB has been seeded } context.Person.AddRange( new Person { Name = "Vlatko", Surname = "Kocev", Address = "s.Oraovica, Radovis", Email = "*****@*****.**", PhoneNumber = "070123456" }, new Person { Name = "Ivana", Surname = "Jovanova", Address = "Moskovska 25, Skopje", Email = "*****@*****.**", PhoneNumber = "+38978999777" }, new Person { Name = "Goran", Surname = "Todorov", Address = "Goce Delcev 2, Bitola", Email = "*****@*****.**", PhoneNumber = "075570057" }, new Person { Name = "Ilija", Surname = "Aleksov", Address = "Pitu Guli 8, Ohrid", Email = "", PhoneNumber = "071 555 678" } ); context.SaveChanges(); } }
public void SetUpMockedDbContext() { _dbContext = new DirectoryContext(new DbContextOptionsBuilder <DirectoryContext>() .UseInMemoryDatabase("directory") .EnableSensitiveDataLogging() .EnableDetailedErrors() .Options); _dbContext.Database.EnsureCreated(); _dbContext.Position.Add(new Position { Id = 1, Name = "President" }); _dbContext.SaveChanges(); }
public void SetUpMockedDbContext() { _dbContext = new DirectoryContext(new DbContextOptionsBuilder <DirectoryContext>() .UseInMemoryDatabase("directory") .EnableSensitiveDataLogging() .EnableDetailedErrors() .Options); _dbContext.Database.EnsureCreated(); _dbContext.Major.Add(new Major { Id = 1, Name = "Software Engineering" }); _dbContext.Minor.Add(new Minor { Id = 1, Name = "A minor" }); _dbContext.SaveChanges(); }
public void InactiveBrother_IsNotInListOfActiveBrothers() { int id = _dbContext.Brother.Add(new Brother { FirstName = "First", LastName = "Last", ExpectedGraduation = DateTime.MaxValue }).Entity.Id; _dbContext.InactiveBrother.Add(new InactiveBrother { Id = id, Reason = "dropped out" }); _dbContext.SaveChanges(); BrotherController controller = new BrotherController(_dbContext, null, null); ContentModel <MinimalBrother> result = (controller.GetBrothers() as OkObjectResult)?.Value as ContentModel <MinimalBrother>; Assert.Multiple(() => { Assert.That(result, Is.Not.Null); Assert.That(result.Content.Count(), Is.EqualTo(0)); Assert.That(result.Content.All(b => b.Id != id)); }); }
public void Setup() { _dbContext = new DirectoryContext(new DbContextOptionsBuilder <DirectoryContext>() .UseInMemoryDatabase("directory") .EnableSensitiveDataLogging() .EnableDetailedErrors() .Options); _dbContext.Database.EnsureCreated(); _dbContext.Brother.AddRange(new[] { new Brother { Id = 1 }, new Brother { Id = 2 } }); _dbContext.SaveChanges(); }
public void SetUpMockedDbContext() { _dbContext = new DirectoryContext(new DbContextOptionsBuilder <DirectoryContext>() .UseInMemoryDatabase("directory") .EnableSensitiveDataLogging() .EnableDetailedErrors() .Options); _dbContext.Database.EnsureCreated(); _dbContext.Brother.AddRange(new[] { new Brother { Id = 1, FirstName = "InactiveFirst", LastName = "InactiveLast", ExpectedGraduation = DateTime.MaxValue }, new Brother { Id = 2, FirstName = "First", LastName = "Last", ExpectedGraduation = DateTime.MaxValue }, new Brother { Id = 3, FirstName = "Grad", LastName = "GradLast", ExpectedGraduation = DateTime.MaxValue }, new Brother { Id = 4, FirstName = "UniqueFirst", LastName = "UniqueLast" }, new Brother { Id = 5, FirstName = "DuplicatedFirst1", LastName = "DuplicatedLast1" }, new Brother { Id = 6, FirstName = "DuplicatedFirst2", LastName = "DuplicatedLast2" } }); _dbContext.InactiveBrother.Add(new InactiveBrother { Id = 1, Reason = "Dropped out" }); _dbContext.SaveChanges(); }
private void CommitChanges() { db.SaveChanges(); }
public int SaveChanges(string user) => _context.SaveChanges(user);
public void AddNewOrganization(OrganizationEntity organizationEntity) { _directoryContext.OrganizationEntities.Add(organizationEntity); _directoryContext.SaveChanges(); }
public void AddCommunicationType(CommunicationTypeEntity communicationMethodEntity) { _directoryContext.CommunicationTypeEntities.Add(communicationMethodEntity); _directoryContext.SaveChanges(); }
public void AddContact(ContactEntity contactEntity) { _directoryContext.ContactEntities.Add(contactEntity); _directoryContext.SaveChanges(); }