public ActionResult Register(Models.User user) { if (ModelState.IsValid) { using (var db = new TodoAppDbContext()) { User userFound = db.Users.SingleOrDefault(u => u.Username == user.Username); if (userFound != null) { ViewBag.Error("User exist"); return(RedirectToAction("Index", "Home")); } db.Users.Add(new Models.User { Email = user.Email, Username = user.Username, Password = Crypto.HashPassword(user.Password) }); db.SaveChanges(); SignIn(user); } } else { ModelState.AddModelError("", "Data is incorrect"); } return(RedirectToAction("Index", "Home")); }
public ActionResult Manage(Client client) { if (string.IsNullOrEmpty(client.Client_ID)) { client.Client_ID = Guid.NewGuid().ToString(); } if (string.IsNullOrEmpty(client.Client_Secret)) { client.Client_Secret = Guid.NewGuid().ToString(); } using (var db = new TodoAppDbContext()) { User user = db.Users.SingleOrDefault(u => u.Username == User.Identity.Name); db.Clients.Add(new Client { Client_ID = client.Client_ID, Client_Secret = Guid.NewGuid().ToString(), Redirect_URI = client.Redirect_URI, Created_On = DateTime.Now, User = user }); db.SaveChanges(); } return(RedirectToAction("Manage", "Home")); }
public ActionResult AddClient(Client client) { if (ModelState.IsValid) { using (var db = new TodoAppDbContext()) { db.Clients.Add(new Client { ClientID = client.ClientID, Client_Secret = client.Client_Secret, Redirect_URI = client.Redirect_URI, Created_On = DateTime.Now, UserID = User.Identity.GetUserId <int>() }); db.SaveChanges(); } } else { ModelState.AddModelError("", "Data is incorrect"); } return(RedirectToAction("Manage", "Home")); }
public void Delete() { using (var db = new TodoAppDbContext()) { db.Database.ExecuteSqlCommand("TRUNCATE TABLE [Tasks]"); db.SaveChanges(); } }
public async Task <bool> AddAsync(TodoItem item) { if (item == null) { _logger.LogError("TodoItem cannot be null"); return(false); } bool result = false; await _context.TodoItems.AddAsync(item); _logger.LogDebug("adding todo item '{description}'", item.Description); result = _context.SaveChanges() > 0; return(result); }
public void Delete(int id) { using (var db = new TodoAppDbContext()) { var task = db.Tasks.SingleOrDefault(t => t.TaskID == id); db.Tasks.Remove(task); db.SaveChanges(); } }
public void Put(int id, Task newTask) { using (var db = new TodoAppDbContext()) { var task = db.Tasks.SingleOrDefault(t => t.TaskID == id); task.Name = newTask.Name; db.SaveChanges(); } }
/// <summary> /// Creates an entity /// </summary> /// <param name="entity"></param> /// <returns></returns> public async Task <T> Create(T entity) { using (TodoAppDbContext context = _contextFactory.CreateDbContext()) { var createdEntity = context.Set <T>().Add(entity); context.SaveChanges(); return(createdEntity); } }
/// <summary> /// Deletes task /// </summary> /// <param name="id"></param> /// <returns></returns> public async Task <bool> Delete(int id) { using (TodoAppDbContext context = _contextFactory.CreateDbContext()) { TaskModel entity = context.Set <TaskModel>().FirstOrDefault((e) => e.Id == id); context.Set <TaskModel>().Remove(entity); context.SaveChanges(); return(true); } }
protected void OnClick(object sender, EventArgs e) { var name = this.TbCategoryName.Text; var cat = new Category() { Name = name }; var ds = new TodoAppDbContext(); ds.Categories.Add(cat); ds.SaveChanges(); }
public void Post(Task task) { using (var db = new TodoAppDbContext()) { db.Tasks.Add(new Task { Name = task.Name, Created_On = DateTime.Now, User = db.Users.SingleOrDefault(u => u.Username == User.Identity.Name) }); db.SaveChanges(); } }