Example #1
0
        public ActionResult Create(USER user)
        {
            if (ModelState.IsValid)
            {
                db.USERS.Add(user);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(user));
        }
Example #2
0
        public ActionResult Create(TASK task)
        {
            if (ModelState.IsValid)
            {
                db.TASKS.Add(task);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.USER = new SelectList(db.USERS, "ID_USER", "NAME", task.USER);
            return(View(task));
        }
        public int SaveTask(Task task)
        {
            ToDoListEntities dbModel = new ToDoListEntities();
            Task             taskadded;

            if (task.TaskId > 0)
            {
                taskadded = dbModel.Tasks.Find(task.TaskId);
                if (taskadded != null)
                {
                    taskadded.TaskName     = task.TaskName;
                    taskadded.DueDate      = task.DueDate;
                    taskadded.Priority     = task.Priority;
                    taskadded.IsCompleted  = task.IsCompleted;
                    taskadded.ProjectRefId = task.ProjectRefId;
                    taskadded.Changed      = DateTime.Now;
                }
            }
            else
            {
                task.Changed = DateTime.Now;
                task.Created = DateTime.Now;
                taskadded    = dbModel.Tasks.Add(task);
            }
            dbModel.SaveChanges();
            UpdateProjectCount(task.ProjectRefId, dbModel);
            return(taskadded.TaskId);
        }
        public HttpResponseMessage UpdateListItemDone(ListItem li)
        {
            ToDoListEntities dc  = new ToDoListEntities();
            ListItem         _li = dc.ListItems.Find(li.Id);

            if (_li == null)
            {
                return(new HttpResponseMessage(System.Net.HttpStatusCode.NotFound));
            }

            if (_li.ItemDone == false)
            {
                _li.ItemDone = true;
            }
            else
            {
                _li.ItemDone = false;
            }

            try
            {
                dc.SaveChanges();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                return(new HttpResponseMessage(System.Net.HttpStatusCode.BadRequest));
            }
            return(new HttpResponseMessage(System.Net.HttpStatusCode.OK));
        }
Example #5
0
        private void SaveItem_Click(object sender, RoutedEventArgs e)
        {
            ToDoListEntities dbEntities = new ToDoListEntities();
            var selected = lvToDoListItem.SelectedItems.Cast <Object>().ToArray();

            if (selected.Length == 0)
            {
                MessageBox.Show("Please select the row you want to update.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            foreach (var item in selected)
            {
                ToDoListItems todo = dbEntities.ToDoListItems.Find(((ToDoList.Business.TodoListItems)item).ItemId);



                if (((ToDoList.Business.TodoListItems)selected[0]).Status == true)
                {
                    todo.Status = "1";
                }
                else
                {
                    todo.Status = "0";
                }
                dbEntities.SaveChanges();
            }
        }
Example #6
0
        public void CreateUserAccount(string _Namesurname, string _Username, string _Password, string _Email)
        {
            string encryptingPassword = Encrypting(_Password).Trim();

            try
            {
                using (ToDoListEntities dbEntities = new ToDoListEntities())
                {
                    var UserNamedb = (from x in dbEntities.Users
                                      where (x.Username == _Username)
                                      select x).FirstOrDefault <Users>();
                    if (UserNamedb == null)
                    {
                        Users user = new Users();
                        user.NameSurname = _Namesurname.Trim();
                        user.Username    = _Username.Trim();
                        user.Password    = encryptingPassword;
                        user.Email       = _Email.Trim();
                        dbEntities.Users.Add(user);
                        dbEntities.SaveChanges();

                        MessageBox.Show("Adding Success!", "Information", MessageBoxButton.OK, MessageBoxImage.Information);
                    }
                    else
                    {
                        MessageBox.Show("This user name is already exists!", "Information", MessageBoxButton.OK, MessageBoxImage.Information);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Adding Failed!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        private static void UpdateProjectCount(int projectId, ToDoListEntities dbModel)
        {
            int     unFinishedTask = dbModel.Tasks.Count(tCount => tCount.ProjectRefId == projectId && tCount.IsCompleted == false);
            Project dbProject      = dbModel.Projects.Find(projectId);

            dbProject.Count = unFinishedTask;
            dbModel.SaveChanges();
        }
Example #8
0
        public ActionResult SaveNewTask(Task newtask)
        {
            ToDoListEntities ORM = new ToDoListEntities();

            ORM.Tasks.Add(newtask);
            ORM.SaveChanges();
            return(RedirectToAction("Index"));
        }
Example #9
0
 public void ClearAllTasks()
 {
     using (var context = new ToDoListEntities())
     {
         context.Database.ExecuteSqlCommand("TRUNCATE TABLE [ToDoTask]");
         context.SaveChanges();
     }
 }
Example #10
0
        public ActionResult DeleteTask(int taskID)
        {
            ToDoListEntities ORM          = new ToDoListEntities();
            Task             TaskToDelete = ORM.Tasks.Find(taskID);

            ORM.Tasks.Remove(TaskToDelete);
            ORM.SaveChanges();
            return(RedirectToAction("Index"));
        }
Example #11
0
 public bool AddTask(Task newTask)
 {
     using (var _TaskContext = new ToDoListEntities())
     {
         _TaskContext.Tasks.Add(newTask);
         _TaskContext.SaveChanges();
     }
     return(true);
 }
Example #12
0
        public ActionResult MarkDone(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Task task = db.Tasks.Find(id);

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

            task.TaskDone        = true;
            db.Entry(task).State = EntityState.Modified;
            db.SaveChanges();

            return(RedirectToAction("Index"));
        }
        public bool DeleteTask(int taskId)
        {
            ToDoListEntities dbModel  = new ToDoListEntities();
            Task             taskFind = dbModel.Tasks.Find(taskId);

            if (taskFind != null)
            {
                dbModel.Tasks.Remove(taskFind);
                dbModel.SaveChanges();
            }
            return(true);
        }
Example #14
0
        public bool DeleteProject(int projectId)
        {
            ToDoListEntities dbModel     = new ToDoListEntities();
            Project          projectFind = dbModel.Projects.Find(projectId);

            if (projectFind != null)
            {
                dbModel.Projects.Remove(projectFind);
                dbModel.SaveChanges();
            }
            return(true);
        }
Example #15
0
 public ToDoTask Update(ToDoTask task)
 {
     using (var context = new ToDoListEntities())
     {
         context.ToDoTasks.Attach(task);
         var entry = context.Entry(task);
         entry.State = EntityState.Modified;
         entry.Property(e => e.ToDoListID).IsModified = false;
         context.SaveChanges();
         return(task);
     }
 }
Example #16
0
        private void DeleteItem_Click(object sender, RoutedEventArgs e)
        {
            ToDoListEntities dbEntities = new ToDoListEntities();
            var selected = lvToDoListItem.SelectedItems.Cast <Object>().ToArray();

            foreach (var item in selected)
            {
                lvToDoListItem.Items.Remove(item);
                ToDoListItems todo = dbEntities.ToDoListItems.Find(((ToDoList.Business.TodoListItems)item).ItemId);
                todo.IsActive = "0";
                dbEntities.SaveChanges();
            }
        }
Example #17
0
 public bool DeleteTask(int taskId)
 {
     using (var _TaskContext = new ToDoListEntities())
     {
         var query = from task in _TaskContext.Tasks
                     where task.Id == taskId
                     select task;
         Task selectedTask = query.First();
         _TaskContext.Tasks.Remove(selectedTask);
         _TaskContext.SaveChanges();
     }
     return(true);
 }
Example #18
0
        public void Remove(int taskId)
        {
            ToDoTask task = new ToDoTask()
            {
                ToDoTaskID = taskId
            };

            using (var context = new ToDoListEntities())
            {
                context.ToDoTasks.Attach(task);
                context.ToDoTasks.Remove(task);
                context.SaveChanges();
            }
        }
        public bool MarkCompleted(Task task)
        {
            ToDoListEntities dbModel = new ToDoListEntities();
            var taskFindDb           = dbModel.Tasks.Find(task.TaskId);

            if (taskFindDb != null)
            {
                taskFindDb.IsCompleted = true;
                dbModel.SaveChanges();
                int projectId = taskFindDb.ProjectRefId;
                UpdateProjectCount(projectId, dbModel);
            }
            return(true);
        }
Example #20
0
 public bool CompleteTask(int taskId)
 {
     using (var _TaskContext = new ToDoListEntities())
     {
         var query = from task in _TaskContext.Tasks
                     where task.Id == taskId
                     select task;
         Task selectedTask = query.First();
         selectedTask.Status        = true;
         selectedTask.DateCompleted = DateTime.Now;
         _TaskContext.Tasks.AddOrUpdate(selectedTask);
         _TaskContext.SaveChanges();
     }
     return(true);
 }
Example #21
0
        public ToDoTask Add(ToDoTask task)
        {
            using (var context = new ToDoListEntities())
            {
                context.ToDoTasks.Add(task);
                context.SaveChanges();

                var data = from t in context.ToDoTasks
                           where t.ToDoTaskID == 1
                           select t;

                //TODO - use a DTO (is it necessary if using poco????)
                ToDoDto dto = new ToDoDto(task);
                return(task);
            }
        }
Example #22
0
 public void Save()
 {
     try
     {
         DbContext.SaveChanges();
     }
     catch (Exception ex)
     {
         try
         {
             var validationErrors = ((System.Data.Entity.Validation.DbEntityValidationException)ex).EntityValidationErrors;
         }
         catch
         {
             //ignored
         }
         throw ex;
     }
 }
Example #23
0
        public void AddUserOfListItems(int _ListId, int _UserId)
        {
            try
            {
                using (ToDoListEntities dbEntities = new ToDoListEntities())
                {
                    UsersOfToDoLists todo = new UsersOfToDoLists();
                    todo.ListId = _ListId;
                    todo.UserId = _UserId;
                    dbEntities.UsersOfToDoLists.Add(todo);
                    dbEntities.SaveChanges();

                    MessageBox.Show("Adding Success!", "Information", MessageBoxButton.OK, MessageBoxImage.Information);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Adding Failed!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Example #24
0
        public void AddToDoList(string ListName)
        {
            try
            {
                using (ToDoListEntities dbEntities = new ToDoListEntities())
                {
                    TodoLists todo = new TodoLists();
                    todo.ListName = ListName.Trim();
                    todo.IsActive = "1";
                    dbEntities.TodoLists.Add(todo);
                    dbEntities.SaveChanges();

                    MessageBox.Show("Adding Success!", "Information", MessageBoxButton.OK, MessageBoxImage.Information);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Adding Failed!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        public HttpResponseMessage DeleteListItem(int id)
        {
            ToDoListEntities dc = new ToDoListEntities();
            ListItem         li = dc.ListItems.Find(id);

            if (li == null)
            {
                return(new HttpResponseMessage(System.Net.HttpStatusCode.NotFound));
            }
            dc.ListItems.Remove(li);
            try
            {
                dc.SaveChanges();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                return(new HttpResponseMessage(System.Net.HttpStatusCode.BadRequest));
            }
            return(new HttpResponseMessage(System.Net.HttpStatusCode.OK));
        }
        public HttpResponseMessage PutListItem(ListItem li)
        {
            ToDoListEntities dc  = new ToDoListEntities();
            ListItem         _li = dc.ListItems.Find(li.Id);

            if (_li == null)
            {
                return(new HttpResponseMessage(System.Net.HttpStatusCode.NotFound));
            }
            _li.ItemText = li.ItemText;

            try
            {
                dc.SaveChanges();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                return(new HttpResponseMessage(System.Net.HttpStatusCode.BadRequest));
            }
            return(new HttpResponseMessage(System.Net.HttpStatusCode.OK));
        }
        public void AddToDoListItems(string _ListItemName, string _Descrption, DateTime _Deadline, int _listId)
        {
            try
            {
                using (ToDoListEntities dbEntities = new ToDoListEntities())
                {
                    ToDoListItems todo = new ToDoListItems();
                    todo.ListItemName = _ListItemName.Trim();
                    todo.Description  = _Descrption.Trim();
                    todo.Deadline     = _Deadline;
                    todo.ListId       = _listId;
                    todo.IsActive     = "1";
                    dbEntities.ToDoListItems.Add(todo);
                    dbEntities.SaveChanges();

                    MessageBox.Show("Adding Success!", "Information", MessageBoxButton.OK, MessageBoxImage.Information);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Adding Failed!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        public HttpResponseMessage PostListItem(ListItem li)
        {
            if (li == null)
            {
                return(new HttpResponseMessage(System.Net.HttpStatusCode.BadRequest));
            }

            Console.WriteLine(li);

            ToDoListEntities dc = new ToDoListEntities();

            dc.ListItems.Add(li);
            try
            {
                dc.SaveChanges();
                return(new HttpResponseMessage(System.Net.HttpStatusCode.Created));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                return(new HttpResponseMessage(System.Net.HttpStatusCode.BadRequest));
            }
        }
Example #29
0
        public int SaveProject(Project project)
        {
            ToDoListEntities dbModel = new ToDoListEntities();
            Project          projectadded;

            if (project.ProjectId > 0)
            {
                projectadded = dbModel.Projects.Find(project.ProjectId);
                if (projectadded != null)
                {
                    projectadded.ProjectName = project.ProjectName;
                    projectadded.Changed     = DateTime.Now;
                }
            }
            else
            {
                project.Changed = DateTime.Now;
                project.Created = DateTime.Now;
                projectadded    = dbModel.Projects.Add(project);
            }

            dbModel.SaveChanges();
            return(projectadded.ProjectId);
        }
Example #30
0
 public JsonResult Ekle(DoList doList)
 {
     db.DoList.Add(doList);
     db.SaveChanges();
     return(Json("1"));
 }