public JsonResponse Create(List list) { if (list == null) { return(new JsonResponse { Result = "Failed", Message = "Create requires an instance of list" }); } if (!ModelState.IsValid) { return(new JsonResponse { Result = "Failed", Message = "Model state is invalid. See data.", Error = ModelState }); } db.Lists.Add(list); db.SaveChanges(); return(new JsonResponse { Message = "Create successful.", Data = list }); }
[HttpPost] //This method is receiving information from the view (in this case, a Super object) public IActionResult AddToDoList(ToDoList toDoList) { _ToDoListDb.ToDoList.Add(toDoList); _ToDoListDb.SaveChanges(); //Needed to save changed made to table. return(RedirectToAction(nameof(Index))); //Returns the Index view with (updated) List }
public JsonResponse Create(User user) { if (user == null) { return(new JsonResponse { Result = "Failed", Message = "Create requires an instance of User" }); } if (!ModelState.IsValid) { return(new JsonResponse { Result = "Failed", Message = "Model state is invalid. See data.", Error = ModelState }); } db.Users.Add(user); db.SaveChanges(); return(new JsonResponse { Message = "Create successful.", Data = user }); }
public void SeedFAQ() { try { var question1 = new FAQ { Question = "What is ToDoList?", Answer = "ToDoList is a Web App for web site content and projects managing." }; var question2 = new FAQ { Question = "Is this available to my country?", Answer = "You can use ToDoList in all countries around the world, at your own risk." }; var question3 = new FAQ { Question = "How do I use the features of ToDoList App?", Answer = "If you want to use ToDoList, you need Azure or any other variant for SQL database and deploying. The code needed you can download from <a href=\"https://github.com/elvyra/ToDoList.git\" target=\"_blank\">GitHub repository</a>." }; var question4 = new FAQ { Question = "How much do the ToDoList App cost?", Answer = "ToDoList is absolutely free for all purposes (personal, learning and comercial). It was created for learning purposes, so be aware of using it on big data projects. We will appreciate your feedback and error reports, if any occours." }; var question5 = new FAQ { Question = "I have technical problem, who do I email?", Answer = "If you have any question, problem, offer or suggestion, please, contact us via facebook or linked (see the links at the bottom of the page)." }; _context.AddRange(question1, question2, question3, question4, question5); _context.SaveChanges(); _logger.LogInformation("Demo FAQ seeded to database."); } catch (Exception error) { _logger.LogError($"Demo FAQ seeding throw an exception. Error: ${error.Message}"); } }
public IActionResult DeleteConfirmed(int id) { var thisCategory = _db.Categories.FirstOrDefault(categories => categories.CategoryId == id); _db.Categories.Remove(thisCategory); _db.SaveChanges(); return(RedirectToAction("Index")); }
public Board AddBoard(Board board) { _context.Board.Add(board); _context.SaveChanges(); return(_context.Board.Last()); }
public IActionResult DeleteConfirmed(int id) { var thisItem = _db.Items.FirstOrDefault(items => items.ItemId == id); _db.Items.Remove(thisItem); _db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Create(TaskItemViewModel taskItemViewModel) { toDoListDbContext.TaskItems.Add(new Domain.Entities.TaskItem { TaskDescription = taskItemViewModel.TaskDescription, TaskTitle = taskItemViewModel.TaskTitle, TaskDueDate = taskItemViewModel.TaskDueDate, UserId = User.Identity.GetUserId() }); toDoListDbContext.SaveChanges(); return(RedirectToAction("TaskList")); }
public ToDoListModel Create(ToDoListModel model, string login) { var user = _dbContext.Users.Include(x => x.ToDoLists).SingleOrDefault(x => x.Login == login); var newToDo = _mapper.Map <DAL.Entities.ToDoList>(model); newToDo.CreationDate = DateTime.Now; user?.ToDoLists.Add(newToDo); _dbContext.SaveChanges(); return(model); }
public IActionResult Create(Category category) { if (ModelState.IsValid) { _context.Categories.Add(category); _context.SaveChanges(); return(RedirectToAction("Index")); } return(View(category)); }
public IActionResult Create(Item item) { if (ModelState.IsValid) { _context.Items.Add(item); _context.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.Categories = new SelectList(_context.Categories, "Categories", "Name"); return(View(item)); }
public ActionResult Create([Bind(Include = "Id,Name,DueDate,IsReOccuring")] ToDoList toDoList) { if (ModelState.IsValid) { db.ToDoLists.Add(toDoList); db.SaveChanges(); return(RedirectToAction("Index")); //After an item added return to index Action -List } return(View(toDoList)); }
public IActionResult AddToDoList(ToDoList todoList) { string activeUserId = User.FindFirst(ClaimTypes.NameIdentifier).Value; if (ModelState.IsValid) { todoList.UserId = activeUserId; _todoContext.ToDoList.Add(todoList); _todoContext.SaveChanges();//dont forget this saves it back to sql } return(RedirectToAction("ToDoList"));//RedirectTo Action goes to method index }
private void CreateEditions() { var defaultEdition = _context.Editions.IgnoreQueryFilters().FirstOrDefault(e => e.Name == EditionManager.DefaultEditionName); if (defaultEdition == null) { defaultEdition = new Edition { Name = EditionManager.DefaultEditionName, DisplayName = EditionManager.DefaultEditionName }; _context.Editions.Add(defaultEdition); _context.SaveChanges(); /* Add desired features to the standard edition, if wanted... */ } }
public ActionResult <ToDoListDTO> Create(ToDoListDTO toDoListDTO) { if (toDoListDTO != null) { var toDoList = mapper.Map <ToDoList>(toDoListDTO); context.ToDoLists.Add(toDoList); context.SaveChanges(); toDoListDTO = mapper.Map <ToDoListDTO>(toDoList); return(toDoListDTO); } else { return(BadRequest()); } }
public async Task <IActionResult> Post([FromBody] ListItem value) { await _context.ListItems.AddAsync(value); _context.SaveChanges(); return(CreatedAtRoute("Get", new { value.Id }, value)); }
public TaskItem AddTaskItem(int boardId, TaskItem taskitem) { var boardTaskItem = new BoardTaskItem(); boardTaskItem.BoardId = boardId; boardTaskItem.TaskItem = taskitem; boardTaskItem.TaskItemId = taskitem.Id; _context.TaskItem.Add(taskitem); _context.BoardTaskItem.Add(boardTaskItem); _context.SaveChanges(); return(_context.TaskItem.Last()); }
public void Create() { new DefaultEditionCreator(_context).Create(); new DefaultLanguagesCreator(_context).Create(); new HostRoleAndUserCreator(_context).Create(); new DefaultSettingsCreator(_context).Create(); _context.SaveChanges(); }
private void AddLanguageIfNotExists(ApplicationLanguage language) { if (_context.Languages.IgnoreQueryFilters().Any(l => l.TenantId == language.TenantId && l.Name == language.Name)) { return; } _context.Languages.Add(language); _context.SaveChanges(); }
public ActionResult Delete(Task task) { using (ToDoListDbContext db = new ToDoListDbContext()) { db.Tasks.Attach(task); db.Entry(task).State = EntityState.Deleted; db.SaveChanges(); return(RedirectToAction("Index")); } }
private void AddSettingIfNotExists(string name, string value, int?tenantId = null) { if (_context.Settings.IgnoreQueryFilters().Any(s => s.Name == name && s.TenantId == tenantId && s.UserId == null)) { return; } _context.Settings.Add(new Setting(tenantId, null, name, value)); _context.SaveChanges(); }
public Task MarkDone(Guid id) { var taskInDb = _context.Tasks.SingleOrDefault(t => t.Id == id); if (taskInDb != null) { try { taskInDb.Status = Status.Done; _context.SaveChanges(); return(taskInDb); } catch (Exception) { _logger.LogError($"Error on task editing occoured. Task {id}"); return(null); } } _logger.LogError($"Task with Id {id} not found"); return(null); }
public void AddTaskToList(int listItemId, ToDoListTask task) { _log.Debug("Check task is null"); if (task == null) { _log.Error("Task not added"); throw new ArgumentNullException("Task not added"); } _log.Debug("Check value taskText is empty"); if (string.IsNullOrEmpty(task.Text)) { _log.Error("Field Text is empty"); throw new ToDoListException("Field Text is empty"); } _log.Debug("Check list exist in db"); var list = _db.ToDoListItems.FirstOrDefault(l => l.Id == listItemId); _log.Debug("Check list is null"); if (list == null) { _log.ErrorFormat("List with id {0} not found", listItemId); throw new ToDoListException(String.Format("List with id {0} not found", listItemId)); } task.ToDoListItem = list; _log.Debug("Add task to list Tasks"); list.Tasks.Add(task); _log.Debug("Add task to db"); _db.SaveChanges(); _log.Info("Task added to db"); }
public ActionResult Create(Task task) { if (!ModelState.IsValid) { return(View(task)); } using (ToDoListDbContext db = new ToDoListDbContext()) { db.Entry(task).State = EntityState.Added; db.SaveChanges(); } return(RedirectToAction("Index")); }
public Person DeleteUserByEmail(string email) { var person = _context.Persons.FirstOrDefaultAsync(p => p.Email == email).Result; if (person == null) { _logger.LogError($"Person with email {email} not found"); return(null); } try { _context.Persons.Remove(person); _context.SaveChanges(); return(person); } catch (Exception err) { _logger.LogError($"Error occoured while trying to remove person with email {email}: {err.Message}"); return(null); } }
public ActionResult <ToDoItemDTO> Create(ToDoItemDTO toDoItemDTO) { if (toDoItemDTO != null) { var toDoList = context.ToDoLists.Find(toDoItemDTO.ToDoListId); if (toDoList != null) { var toDoItem = mapper.Map <ToDoItem>(toDoItemDTO); context.ToDoItems.Add(toDoItem); context.SaveChanges(); toDoItemDTO = mapper.Map <ToDoItemDTO>(toDoItem); return(toDoItemDTO); } else { return(BadRequest("ToDoList Not found!")); } } else { return(BadRequest()); } }
private void CreateDefaultTenant() { // Default tenant var defaultTenant = _context.Tenants.IgnoreQueryFilters().FirstOrDefault(t => t.TenancyName == AbpTenantBase.DefaultTenantName); if (defaultTenant == null) { defaultTenant = new Tenant(AbpTenantBase.DefaultTenantName, AbpTenantBase.DefaultTenantName); var defaultEdition = _context.Editions.IgnoreQueryFilters().FirstOrDefault(e => e.Name == EditionManager.DefaultEditionName); if (defaultEdition != null) { defaultTenant.EditionId = defaultEdition.Id; } _context.Tenants.Add(defaultTenant); _context.SaveChanges(); } }
public void Create(User user) { _log.Debug("Check user is null"); if (user == null) { _log.Error("Account not created."); throw new CreateUserFailedException("Account not created."); } _log.Debug("Check username or password or firstname or lastname or emailaddress are empty "); if (string.IsNullOrEmpty(user.Username) || string.IsNullOrEmpty(user.Password) || string.IsNullOrEmpty(user.FirstName) || string.IsNullOrEmpty(user.LastName) || string.IsNullOrEmpty(user.EmailAddress)) { _log.Error("Field is empty"); throw new CreateUserFailedException("Fill in all fields."); } _log.Debug("Add user to db"); _db.Users.Add(user); _db.SaveChanges(); _log.Info("User added to db"); }
public Notes AddNote(Notes note) { _dbContext.Notes.Add(note); _dbContext.SaveChanges(); return(note); }
private void CreateHostRoleAndUsers() { // Admin role for host var adminRoleForHost = _context.Roles.IgnoreQueryFilters().FirstOrDefault(r => r.TenantId == null && r.Name == StaticRoleNames.Host.Admin); if (adminRoleForHost == null) { adminRoleForHost = _context.Roles.Add(new Role(null, StaticRoleNames.Host.Admin, StaticRoleNames.Host.Admin) { IsStatic = true, IsDefault = true }).Entity; _context.SaveChanges(); } // Grant all permissions to admin role for host var grantedPermissions = _context.Permissions.IgnoreQueryFilters() .OfType <RolePermissionSetting>() .Where(p => p.TenantId == null && p.RoleId == adminRoleForHost.Id) .Select(p => p.Name) .ToList(); var permissions = PermissionFinder .GetAllPermissions(new ToDoListAuthorizationProvider()) .Where(p => p.MultiTenancySides.HasFlag(MultiTenancySides.Host) && !grantedPermissions.Contains(p.Name)) .ToList(); if (permissions.Any()) { _context.Permissions.AddRange( permissions.Select(permission => new RolePermissionSetting { TenantId = null, Name = permission.Name, IsGranted = true, RoleId = adminRoleForHost.Id }) ); _context.SaveChanges(); } // Admin user for host var adminUserForHost = _context.Users.IgnoreQueryFilters().FirstOrDefault(u => u.TenantId == null && u.UserName == AbpUserBase.AdminUserName); if (adminUserForHost == null) { var user = new User { TenantId = null, UserName = AbpUserBase.AdminUserName, Name = "admin", Surname = "admin", EmailAddress = "*****@*****.**", IsEmailConfirmed = true, IsActive = true }; user.Password = new PasswordHasher <User>(new OptionsWrapper <PasswordHasherOptions>(new PasswordHasherOptions())).HashPassword(user, "123qwe"); user.SetNormalizedNames(); adminUserForHost = _context.Users.Add(user).Entity; _context.SaveChanges(); // Assign Admin role to admin user _context.UserRoles.Add(new UserRole(null, adminUserForHost.Id, adminRoleForHost.Id)); _context.SaveChanges(); _context.SaveChanges(); } }