コード例 #1
0
ファイル: HomeController.cs プロジェクト: zaltiparmakov/oauth
        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"));
        }
コード例 #2
0
ファイル: HomeController.cs プロジェクト: zaltiparmakov/oauth
        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"));
        }
コード例 #3
0
ファイル: HomeController.cs プロジェクト: zaltiparmakov/oauth
        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"));
        }
コード例 #4
0
 public void Delete()
 {
     using (var db = new TodoAppDbContext())
     {
         db.Database.ExecuteSqlCommand("TRUNCATE TABLE [Tasks]");
         db.SaveChanges();
     }
 }
コード例 #5
0
        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);
        }
コード例 #6
0
 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();
     }
 }
コード例 #7
0
 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();
     }
 }
コード例 #8
0
ファイル: GenericDataService.cs プロジェクト: DcBD/TodoApp
        /// <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);
            }
        }
コード例 #9
0
        /// <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);
            }
        }
コード例 #10
0
        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();
        }
コード例 #11
0
        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();
            }
        }