Esempio n. 1
0
        public ValidationResponse CreateTodo(CreateTodoRequest request)
        {
            ValidationResponse response = new ValidationResponse();

            if (request == null || string.IsNullOrWhiteSpace(request.Username) || string.IsNullOrWhiteSpace(request.Token))
            {
                response.Error = "Need to login";
                return(response);
            }

            User user = context.Users.FirstOrDefault(u => u.Name == request.Username && u.Token == request.Token);

            if (user == null)
            {
                response.Error = "Need to login";
                return(response);
            }

            var todo = new ToDo();

            todo.User = user;
            todo.Text = request.TodoText;
            context.Entry(todo).State = EntityState.Added;
            context.SaveChanges();

            return(response);
        }
Esempio n. 2
0
        public RegisterResponse Register(RegisterRequest registerRequest)
        {
            RegisterResponse response = new RegisterResponse();

            if (string.IsNullOrWhiteSpace(registerRequest.Username))
            {
                response.Error = "Username is empty";
                return(response);
            }
            if (string.IsNullOrWhiteSpace(registerRequest.Password))
            {
                response.Error = "Password is empty";
                return(response);
            }
            User user;

            if (context.Users.Any())
            {
                user = context.Users.FirstOrDefault(p => p.Name.ToLower() == registerRequest.Username.ToLower());
                if (user != null)
                {
                    response.Error = "User already exists";
                    return(response);
                }
            }

            user                      = new User();
            user.Name                 = registerRequest.Username;
            user.Password             = registerRequest.Password;
            user.Token                = Guid.NewGuid().ToString();
            context.Entry(user).State = EntityState.Added;
            context.SaveChanges();
            response.Token = user.Token;
            return(response);
        }
Esempio n. 3
0
        /// <summary>
        /// DB method to Soft delete(Mark complete) a task
        /// </summary>
        /// <param name="toDoID"></param>
        /// <returns></returns>
        public long Update(long toDoID)
        {
            ToDo todo = _toDoDbContext.todoS.Find(toDoID);

            if (todo != null)
            {
                todo.isDeleted = true;
                _toDoDbContext.Entry(todo).State = EntityState.Modified;
                if (_toDoDbContext.SaveChanges() == 1)
                {
                    return(todo.Id);
                }
            }
            return(0);
        }
Esempio n. 4
0
        public async Task <IActionResult> PutToDoItem(int id, ToDoItem toDoItem)
        {
            if (id != toDoItem.ToDoItemId)
            {
                return(BadRequest());
            }

            _context.Entry(toDoItem).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ToDoItemExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Esempio n. 5
0
        public async Task <IActionResult> PutToDo([FromRoute] int id, [FromBody] ToDo toDo)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != toDo.ToDoId)
            {
                return(BadRequest());
            }

            _context.Entry(toDo).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ToDoExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Esempio n. 6
0
        public IHttpActionResult PutAspNetUser(string id, AspNetUser aspNetUser)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != aspNetUser.Id)
            {
                return(BadRequest());
            }

            db.Entry(aspNetUser).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AspNetUserExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public async Task <IHttpActionResult> PutToDoItem(int id, ToDoItem toDoItem)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != toDoItem.ToDoItemID)
            {
                return(BadRequest());
            }

            db.Entry(toDoItem).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ToDoItemExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Esempio n. 8
0
        public async Task <IActionResult> PutUser(int id, User user)
        {
            if (id != user.UserId)
            {
                return(BadRequest());
            }

            _context.Entry(user).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!UserExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Esempio n. 9
0
 public ActionResult Edit([Bind(Include = "Id,Name,Description")] ToDoItem toDoItem)
 {
     if (ModelState.IsValid)
     {
         db.Entry(toDoItem).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(toDoItem));
 }
 public ActionResult Edit([Bind(Include = "ID,Item,Completed")] ToDoItem toDoItem)
 {
     if (ModelState.IsValid)
     {
         _db.Entry(toDoItem).State = EntityState.Modified;
         _db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(toDoItem));
 }
Esempio n. 11
0
        public async Task <ActionResult> Edit([Bind(Include = "ToDoItemID,Title,Status")] ToDoItem toDoItem)
        {
            if (ModelState.IsValid)
            {
                db.Entry(toDoItem).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(toDoItem));
        }
Esempio n. 12
0
        public void Done(int?id)
        {
            var task = GetTask(id);

            if (task == null)
            {
                return;
            }

            task.IsDone = true;
            _context.Entry(task).State = EntityState.Modified;
            _context.SaveChanges();
        }
        public async Task <IActionResult> Update([FromRoute] int id, [FromBody] ToDoList list)
        {
            ToDoList toDoList = await _context.ToDoLists.FindAsync(id);

            if (toDoList == null)
            {
                return(RedirectToAction("Create", list));
            }
            list.ID = id;
            _context.Entry(toDoList).State = EntityState.Detached;

            toDoList = list;
            _context.ToDoLists.Update(toDoList);
            await _context.SaveChangesAsync();

            return(NoContent());
        }
Esempio n. 14
0
        public async Task <IActionResult> Update([FromRoute] long id, [FromBody] ToDoItem item)
        {
            ToDoItem todo = await _context.ToDoItems.FindAsync(id);

            if (todo == null)
            {
                return(RedirectToAction("Create", item));
            }
            item.ID = id;
            _context.Entry(todo).State = EntityState.Detached;
            todo = item;

            _context.ToDoItems.Update(todo);
            await _context.SaveChangesAsync();

            return(NoContent());
        }
Esempio n. 15
0
        public async Task <IHttpActionResult> PutTodo(int id, Todo todo)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != todo.Id)
            {
                return(BadRequest());
            }

            if (todo.TodoTask == null)
            {
                todo.TodoTask = _todoDal.GetToDoFromId(id).TodoTask;
            }

            db.Entry(todo).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TodoExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Esempio n. 16
0
 public IActionResult Edit(Item item)
 {
     db.Entry(item).State = EntityState.Modified;
     db.SaveChanges();
     return(RedirectToAction("Index"));
 }
Esempio n. 17
0
 public IActionResult Edit(Category category)
 {
     db.Entry(category).State = EntityState.Modified;
     db.SaveChanges();
     return(RedirectToAction("Index"));
 }
Esempio n. 18
0
 public async Task Update(ToDo toDo)
 {
     _context.Entry(toDo).State = EntityState.Modified;
     await _context.SaveChangesAsync();
 }
Esempio n. 19
0
 public virtual void Update(TEntity entity, string modifiedBy = null)
 {
     context.Set <TEntity>().Attach(entity);
     context.Entry(entity).State = EntityState.Modified;
 }
Esempio n. 20
0
 public DbEntityEntry Entry(object entity)
 {
     return(db.Entry(entity));
 }
 public Item Edit(Item item)
 {
     db.Entry(item).State = EntityState.Modified;
     db.SaveChanges();
     return(item);
 }
Esempio n. 22
0
 public async Task <int> Update(T entity)
 {
     _dbContext.Set <T>().Attach(entity);
     _dbContext.Entry(entity).State = EntityState.Modified;
     return(await Save());
 }