Ejemplo n.º 1
0
 public Task SaveOrUpdateTask(Task task)
 {
     if (task.Id == 0)
         return AddTask(task);
     else
         return UpdateTask(task);
 }
Ejemplo n.º 2
0
 private Task UpdateTask(Task task)
 {
     lock (tasks)
     {
         var taskToUpdate = (from t in GetAll() where t.Id == task.Id select t).First<Task>();
         tasks.Remove(taskToUpdate);
         tasks.Add(task);
     }
     return task;
 }
Ejemplo n.º 3
0
 private Task AddTask(Task task)
 {
     lock (tasks)
     {
         var maxTask = from t in GetAll() where t.Id == GetAll().Max(i => i.Id) select t;
         task.Id = maxTask.First<Task>().Id++;
         tasks.Add(task);
     }
     return task;
 }
Ejemplo n.º 4
0
 public Task SaveOrUpdate(Task task)
 {
     if (task.Id == 0)
     {
         return AddTask(task);
     }
     else
     {
         return UpdateTask(task);
     }
 }
Ejemplo n.º 5
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Task = await _context.Task.SingleOrDefaultAsync(m => m.ID == id);

            if (Task == null)
            {
                return(NotFound());
            }
            return(Page());
        }
Ejemplo n.º 6
0
        private void RegistrationButton_Click(object sender, System.EventArgs e)
        {
            Models.DatabaseContext oDatabaseContext = null;


            try
            {
                oDatabaseContext =
                    new Models.DatabaseContext();

                Models.Task oTask =
                    new Models.Task();


                oTask.TaskTitle = TitleTextBox.Text;

                oTask.TaskDescription = DescriptionTextBox.Text;
                oTask.ImportanceLevel = ImportanceComboBox.Text;
                oTask.Date            = dateTimePicker1.Text;



                oDatabaseContext.Tasks.Add(oTask);

                oDatabaseContext.SaveChanges();


                System.Windows.Forms.MessageBox.Show("کار جدید مورد نظر شما اضافه گردید.");

                TitleTextBox.Text       = string.Empty;
                DescriptionTextBox.Text = string.Empty;
            }
            catch (System.Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("Error: " + ex.Message);
            }
            finally
            {
                if (oDatabaseContext != null)
                {
                    oDatabaseContext.Dispose();
                    oDatabaseContext = null;
                    Main oMian = new Main();
                    oMian.Show();
                }
            }
        }
Ejemplo n.º 7
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Task = await _context.Task.FindAsync(id);

            if (Task != null)
            {
                _context.Task.Remove(Task);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Выполняет запрос на показ всех задач пользователя    
        /// </summary>
        /// <param name="user">Логин пользовотеля для которого выполняется запрос</param>
        /// <returns></returns>
        public IEnumerable<Task> ShowAllTasks(string user)
        {
            //    user = HttpUtility.HtmlEncode(user);
            var listTasks = new List<Task>();
            using (var connection = new SqlConnection(ConnectionString))
            {
                using (var cmd = connection.CreateCommand())
                {
                    connection.Open();
                    cmd.CommandText = @"
                         select
                            id_task
                            ,name_task
                            ,time_when_task_completed
                         from
                            Tasks
                         where
                            (
                            user_login =@login
                            and deleted  = 0
                            and time_when_task_completed is null
                            )
                            or
                            (
                                Tasks.id_task in
                                (
                                select
                                    id_task
                                from
                                    Tasks
                                where
                                    user_login = @login
                                    and deleted  = 0
                                    and time_when_task_completed is not null
                                order by   time_when_task_completed desc
                                    offset 0 rows
                                    fetch next 5 rows only
                                )
                            )
                         ";

                    cmd.Parameters.AddWithValue("@login", user);
                    using (var reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            var task = new Task();
                            task.Id = reader.GetInt32(reader.GetOrdinal("id_task"));
                            task.Name = reader.GetString(reader.GetOrdinal("name_task"));
                       //     task.Name = HttpUtility.HtmlDecode(task.Name);
                            if (reader["time_when_task_completed"] == DBNull.Value)
                                task.TimeWhenTaskCompleted = null;
                            else
                                task.TimeWhenTaskCompleted =
                                    reader.GetDateTime(reader.GetOrdinal("time_when_task_completed"));

                            listTasks.Add(task);
                        };
                    }
                }
            }
            IEnumerable<Task> result = listTasks.OrderBy(x => x.Name);
            return result;
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Ищет задачу в базе по id
        /// </summary>
        /// <param name="id">id задачи</param>    
        /// <returns></returns>
        public Task FindTask(int id)
        {
            var task = new Task();
            using (var connection = new SqlConnection(ConnectionString))
            {
                using (var cmd = connection.CreateCommand())
                {
                    connection.Open();
                    cmd.Parameters.AddWithValue("@id", id);
                    cmd.CommandText = @"
                            select
                                name_task
                                ,deadline
                            from
                                Tasks
                            where
                                id_task=@id";
                    using (var reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            task.Name = reader.GetString(reader.GetOrdinal("name_task"));
                       //     task.Name = HttpUtility.HtmlDecode(task.Name);
                            if (reader["deadline"] == DBNull.Value)
                                task.Deadline = null;
                            else
                                task.Deadline = reader.GetDateTime(reader.GetOrdinal("deadline"));
                        }
                    }
                    var marksList = new List<string>();
                    cmd.CommandText = @"
                            select
                                name_mark
                            from
                                Tasks_Marks
                            where
                                id_task=@id";
                    using (var reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            marksList.Add(reader.GetString(reader.GetOrdinal("name_mark")));
                        }
                    }
                    string marks = string.Empty;
                    foreach (var mark in marksList)
                    {
                        marks += mark + ",";
                    }
                 //   marks = HttpUtility.HtmlDecode(marks);
                    task.Id = id;
                    task.Marks = marks;

                }
            }
            return task;
        }
Ejemplo n.º 10
0
 private Task UpdateTask(Task task)
 {
     db.Entry(task).State = System.Data.EntityState.Modified;
     db.SaveChanges();
     return task;
 }
Ejemplo n.º 11
0
 private Task AddTask(Task task)
 {
     db.Tasks.Add(task);
     db.SaveChanges();
     return task;
 }
Ejemplo n.º 12
0
 private Task AddTask(Task task)
 {
     Task t = context.Tasks.Add(task);
     context.SaveChanges();
     return t;
 }