Exemple #1
0
        public async Task UpdateAsync(Guid id, string title, string description, DateTime term, bool isDone)
        {
            try
            {
                var toUpdateTask = await _context.Task.FindAsync(id);

                toUpdateTask.Title       = title;
                toUpdateTask.Description = description;
                toUpdateTask.Term        = term;
                toUpdateTask.IsDone      = isDone;

                if (toUpdateTask != null)
                {
                    _context.Task.Attach(toUpdateTask);
                    _context.Entry(toUpdateTask).Property(p => p.Title).IsModified       = true;
                    _context.Entry(toUpdateTask).Property(p => p.Description).IsModified = true;
                    _context.Entry(toUpdateTask).Property(p => p.Term).IsModified        = true;
                    _context.Entry(toUpdateTask).Property(p => p.IsDone).IsModified      = true;

                    await _context.SaveChangesAsync();
                }
            }
            catch (Exception ex)
            {
                Debug.Print($"Błąd usuwania zadania z bazy danych {ex}");
            }
        }
Exemple #2
0
        public string Login(string username, string password)
        {
            _log.Debug("Check user exist in db");
            var user = _db.Users.FirstOrDefault(u => u.Username == username && u.Password == password);

            _log.Debug("Check user is null");
            if (user == null)
            {
                _log.Error("Invalid username or password");
                throw new LoginFailedException("Invalid username or password");
            }
            _log.Debug("Check username or password are empty ");
            if (string.IsNullOrEmpty(user.Username) || string.IsNullOrEmpty(user.Password))
            {
                _log.Error("Invalid username or password");
                throw new LoginFailedException("Invalid username or password");
            }

            string token = Guid.NewGuid().ToString();

            _sessionContextManager.SetSessionToken(token);
            _sessionContextManager.SetValue("User", user);

            _db.Entry <User>(user).State = System.Data.Entity.EntityState.Detached;
            _log.Debug("Value loggedUser");
            //_loggedUser = user;
            //_loggedUser = (User)_sessionContextManager.GetValue("User");
            _log.Info("User is logged");

            //string t = _sessionContextManager.GetSessionToken();
            return(_sessionContextManager.GetSessionToken());
        }
        public async Task <IActionResult> PutListItem([FromRoute] int id, [FromBody] ListItem listItem)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(NoContent());
        }
        public ActionResult Delete(TaskItemViewModel taskItemViewModel)
        {
            var taskItem = toDoListDbContext.TaskItems.Where(lmb => lmb.Id == taskItemViewModel.Id).FirstOrDefault();

            toDoListDbContext.Entry(taskItem).State = System.Data.Entity.EntityState.Deleted;
            toDoListDbContext.SaveChanges();
            return(RedirectToAction("TaskList"));
        }
 public ActionResult Edit([Bind(Include = "Id,Name,DueDate,IsReOccuring")] ToDoList toDoList)
 {
     if (ModelState.IsValid)
     {
         db.Entry(toDoList).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));//After an item Edited return to index Action -List
     }
     return(View(toDoList));
 }
 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"));
     }
 }
 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 void RemoveList(int listItemId)
        {
            _log.Debug("Value loggedUser");
            var loggedUser = _securityManager.GetLoggedUser();

            _log.Debug("Check list exist in db");
            var list = _db.ToDoListItems.FirstOrDefault(u => u.Id == listItemId && u.User.Id == loggedUser.Id);

            _log.Debug("Check list is not null");
            if (list != null)
            {
                _log.Debug("Remove list");
                _db.Entry <ToDoListItem>(list).State = System.Data.Entity.EntityState.Deleted;
                _db.SaveChanges();
                _log.Info("Removed list");
            }
            else
            {
                _log.ErrorFormat("List with not found");
                throw new ToDoListException(String.Format("List with not found"));
            }
        }
Exemple #9
0
 public JsonResponse Change(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.Entry(user).State = System.Data.Entity.EntityState.Modified;
     db.SaveChanges();
     return(new JsonResponse {
         Message = "Change successful.",
         Data = user
     });
 }
        public IActionResult SaveChanges(ToDoList updatedToDoList)
        {
            ToDoList toDoList = _ToDoListDb.ToDoList.Find(updatedToDoList.ToDoListId);



            //merging the databaseSuper with the updateSuper one property at a time
            //This is to prevent losing information in the databaseSuper that might not
            //but in the updatedSuper
            toDoList.ToDoListId      = updatedToDoList.ToDoListId;
            toDoList.TaskDescription = updatedToDoList.TaskDescription;
            toDoList.DueDate         = updatedToDoList.DueDate;
            toDoList.Complete        = updatedToDoList.Complete;
            toDoList.UserId          = updatedToDoList.UserId;

            //creates a log of changes for this entry. A way to tracking our work
            _ToDoListDb.Entry(toDoList).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
            _ToDoListDb.Update(toDoList);
            _ToDoListDb.SaveChanges();

            return(RedirectToAction(nameof(Index)));
        }
 public async Task UpdateAsync(T entity)
 {
     _dbContext.Entry(entity).State = EntityState.Modified;
     await _dbContext.SaveChangesAsync();
 }
 public IActionResult Edit(Category category)
 {
     _db.Entry(category).State = EntityState.Modified;
     _db.SaveChanges();
     return(RedirectToAction("Index"));
 }
Exemple #13
0
 public IActionResult Edit(int id, Item item)
 {
     db.Entry(item).State = EntityState.Modified;
     db.SaveChanges();
     return(RedirectToAction("Index"));
 }
 public Item Edit(Item item)
 {
     db.Entry(item).State = EntityState.Modified;
     db.SaveChanges();
     return(item);
 }