Esempio n. 1
0
        public ActionResult EditTask(Task task)
        {
            Task newtask = db.Tasks.Find(task.Id);

            newtask.Complete         = task.Complete;
            newtask.Title            = task.Title;
            newtask.Importance_Level = task.Importance_Level;
            newtask.Description      = task.Description;
            newtask.Due_Date         = task.Due_Date;

            db.Entry(newtask).State = EntityState.Modified;
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Esempio n. 2
0
        public void Add(Task task)
        {
            DbEntityEntry entry = _context.Entry(task);

            if (entry.State != EntityState.Detached)
            {
                entry.State = EntityState.Added;
            }
            else
            {
                _dbSet.Add(task);
                _context.SaveChanges();
            }
        }
Esempio n. 3
0
        public ActionResult ForgetPassword(FormCollection collection)
        {
            var Password        = collection["Password"] ?? string.Empty;
            var ConfirmPassword = collection["ConfirmPassword"] ?? string.Empty;

            if (string.IsNullOrEmpty(Password) || string.IsNullOrEmpty(ConfirmPassword) || Password != ConfirmPassword)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var Email      = Session["Email"].ToString();
            var SecretWord = Session["SecretWord"].ToString();
            var userModel  = new UserModel();

            userModel                 = db.User.Where(x => x.Email == Email && x.SecretWord == SecretWord).FirstOrDefault();
            userModel.Password        = Password;
            userModel.ConfirmPassword = ConfirmPassword;
            userModel.ModifiedDate    = DateTime.Now;

            if (ModelState.IsValid)
            {
                db.Entry(userModel).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(RedirectToAction("Index", "Login"));
        }
Esempio n. 4
0
        public string Login(string userName, string password)
        {
            ToDoContext dbContext = new ToDoContext();

            _logManager.Debug("Login process started");
            var user = dbContext.Users.Where(u => u.Username == userName).SingleOrDefault();

            _logManager.Debug("User with provided username found");
            if (user != null)
            {
                if (password == user.Password)
                {
                    _logManager.Info("Provided credentials are valid ");
                    string token = Guid.NewGuid().ToString();
                    _sessionManager.SessionToken = token;
                    _sessionManager.CreateSession("User", user);

                    dbContext.Entry <User>(user).State = System.Data.Entity.EntityState.Detached;

                    _logManager.Info("User sucsesfully logged in: " + user.Id + " " + user.Username + " " + user.Password);
                    _logManager.Debug("Login process ended successfully");
                    return(_sessionManager.SessionToken);
                }
                else
                {
                    _logManager.Error("Invalid password");
                    throw new PasswordInvalidException("Invalid password");
                }
            }
            else
            {
                _logManager.Error("User cannot be found");
                throw new UserNameNotFoundException("User cannot be found");
            }
        }
Esempio n. 5
0
        public async Task <IHttpActionResult> PutToDoItem(Guid id, ToDoItem toDoItem)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != toDoItem.Id)
            {
                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. 6
0
        public async Task <IActionResult> PutNote([FromRoute] int id, [FromBody] Note note)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != note.Id)
            {
                return(BadRequest());
            }
            //var Notes = _context.Note.Include(s => s.Labels).Include(y => y.CheckLists);
            _context.Entry(note).State = EntityState.Modified;

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

            return(NoContent());
        }
Esempio n. 7
0
        public ToDo Update(ToDo updatedToDo)
        {
            // get the ToDo object in the current list with this id
            var currentToDo = _todoContext.ToDos.Find(updatedToDo.Id);

            // return null if todo to update isn't found
            if (currentToDo == null)
            {
                return(null);
            }

            // NOTE: This method is already completed for you, but note
            // how the property values are copied below.

            // copy the property values from the changed todo into the
            // one in the db. NOTE that this is much simpler than individually
            // copying each property.
            _todoContext.Entry(currentToDo)
            .CurrentValues
            .SetValues(updatedToDo);

            // update the todo and save
            _todoContext.ToDos.Update(currentToDo);
            _todoContext.SaveChanges();
            return(currentToDo);
        }
Esempio n. 8
0
        public async Task <IActionResult> PutToDoList([FromRoute] int id, [FromBody] ToDoList list)
        {
            list.ID = id;
            //ToDoList y = await _context.ToDoLists.FirstOrDefaultAsync(x => x.ID == id);
            //y = list;

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            if (id != list.ID)
            {
                return(BadRequest());
            }
            _context.Entry(list).State = EntityState.Modified;
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ToDoListExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
            return(NoContent());
        }
Esempio n. 9
0
        public async Task <IActionResult> PutAgendaItem([FromRoute] int id, [FromBody] AgendaItem agendaItem)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != agendaItem.AgendaItemId)
            {
                return(BadRequest());
            }

            Context.Entry(agendaItem).State = EntityState.Modified;

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

            return(NoContent());
        }
Esempio n. 10
0
        // PUT api/Default1/5
        public HttpResponseMessage PutToDo(int id, ToDo todo)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }

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

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

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex));
            }

            return(Request.CreateResponse(HttpStatusCode.OK));
        }
        public async Task <IActionResult> PutToDoModel(int id, ToDoModel toDoModel)
        {
            if (id != toDoModel.ID)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Esempio n. 12
0
        public ActionResult AjaxUpdate(int?id, bool value)
        {
            if (Session["LOGGED_USERID"] == null || Session["LOGGED_USERNAME"] == null)
            {
                return(RedirectToAction("Index", "Login"));
            }

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var taskModel = db.Task.Find(id);

            if (taskModel == null)
            {
                return(HttpNotFound());
            }

            taskModel.IsComplete = value;
            if (ModelState.IsValid)
            {
                db.Entry(taskModel).State = EntityState.Modified;
                db.SaveChanges();
            }

            return(PartialView("_ToDoTable", GetTaskModels()));
        }
Esempio n. 13
0
        public async Task <IActionResult> PutTodo([FromRoute] int id, [FromBody] Todo todo)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != todo.Id)
            {
                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. 14
0
        public IHttpActionResult PutToDo(int id, ToDo toDo)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != toDo.Id)
            {
                return(BadRequest());
            }
            if (toDo.IsCompleted)
            {
                toDo.EndDate = DateTime.Now;
            }
            db.Entry(toDo).State = EntityState.Modified;

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Esempio n. 15
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. 16
0
        // PUT api/ToDoTask/5
        public IHttpActionResult PutToDoTask(int id, ToDoTask todotask)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != todotask.ID)
            {
                return(BadRequest());
            }

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Esempio n. 17
0
        public async Task <ActionResult <ToDoItem> > UpdateTask(int id, ToDoItemDto toDoItemDto)
        {
            if (ModelState.IsValid)
            {
                var toDoItem = await _toDoContext.ToDoItems.FindAsync(id);

                if (toDoItem != null)
                {
                    toDoItem.DueDate  = toDoItemDto.DueDate;
                    toDoItem.Label    = toDoItemDto.Label;
                    toDoItem.Status   = toDoItemDto.Status;
                    toDoItem.ToDo     = toDoItemDto.ToDo;
                    toDoItem.DueDate  = toDoItemDto.DueDate;
                    toDoItem.UpdateDt = DateTime.UtcNow;
                    _toDoContext.Attach(toDoItem);
                    _toDoContext.Entry(toDoItem).State = EntityState.Modified;
                    var output = await _toDoContext.SaveChangesAsync();

                    if (output > 0)
                    {
                        return(Ok(toDoItem));
                    }
                }
                return(BadRequest("Item not found"));
            }

            return(BadRequest("Some error happened"));
        }
Esempio n. 18
0
        public async Task <ActionResult <ToDoItem> > EditItem(long id, TodoItemDto dto)
        {
            var entity = await _context.ToDoItems.FindAsync(id);

            if (entity == null)
            {
                return(NotFound());
            }

            if (TodoItemNameExists(dto.name) && entity.id != id)
            {
                return(Conflict());
            }

            entity.name       = dto.name;
            entity.isComplete = dto.isComplete;

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

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

            return(NoContent());
        }
Esempio n. 19
0
        public async Task <IActionResult> PutComment(long id, UpdateCommentDto updateCommentDto)
        {
            if (id != updateCommentDto.Id)
            {
                return(BadRequest());
            }

            var commentEntity = CommentMapper.mapFromUpdateDto(updateCommentDto);

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

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

            return(NoContent());
        }
Esempio n. 20
0
        public async Task <IActionResult> PutFamilles(long id, Familles familles)
        {
            if (id != familles.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Esempio n. 21
0
        public Todo PutTodo(Todo todo)
        {
            ToDoContext context = new ToDoContext();

            context.Entry(todo).State = EntityState.Modified;
            context.SaveChanges();
            return(todo);
        }
Esempio n. 22
0
        public void UpdateItem(ToDoModel toDoModel)
        {
            var todo = toDoModel.ToOrmToDo();

            db.ToDos.Attach(todo);
            db.Entry(todo).State = EntityState.Modified;
            db.SaveChanges();
        }
Esempio n. 23
0
        public void RemoveTask(int id)
        {
            db = new ToDoContext();
            Task task = db.Tasks.ToList().Last(t => t.Id == id);

            db.Entry(task).State = EntityState.Deleted;
            db.SaveChanges();
        }
Esempio n. 24
0
        public Item PutItem(Item item)
        {
            ToDoContext context = new ToDoContext();

            context.Entry(item).State = EntityState.Modified;
            context.SaveChanges();
            return(item);
        }
Esempio n. 25
0
 public void Save(Tablo tablo)
 {
     using (var context = new ToDoContext())
     {
         context.Entry(tablo).State = Microsoft.EntityFrameworkCore.EntityState.Added;
         context.SaveChanges();
     }
 }
Esempio n. 26
0
        void RemoveList(int id)
        {
            db = new ToDoContext();
            CustomList list = db.CustomLists.ToList().Last(l => l.Id == id);

            db.Entry(list).State = EntityState.Deleted;
            db.SaveChanges();
        }
Esempio n. 27
0
 public ActionResult Edit([Bind(Include = "todo_id,todo_title,todo_description,todo_completed,todo_dateadded")] todo_item todo_item)
 {
     if (ModelState.IsValid)
     {
         db.Entry(todo_item).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(todo_item));
 }
Esempio n. 28
0
 public ActionResult Edit([Bind(Include = "Id,Title,Details,Date,IsDone")] ToDo toDo)
 {
     if (ModelState.IsValid)
     {
         db.Entry(toDo).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(toDo));
 }
Esempio n. 29
0
 public ActionResult Edit(ToDoModels todomodels)
 {
     if (ModelState.IsValid)
     {
         db.Entry(todomodels).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(todomodels));
 }
Esempio n. 30
0
 public ActionResult Edit([Bind(Include = "ListID,Title,Date")] List list)
 {
     if (ModelState.IsValid)
     {
         db.Entry(list).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(list));
 }