示例#1
0
        public IHttpActionResult AddTodo([FromBody] Todo todo)
        {
            string method = "POST";

            TodoDTO todoDto = new TodoDTO();

            todoDto.todo_text = todo.todo_text;

            if (!_todoBLL.ValidateTodo(todoDto, method))
            {
                return(BadRequest());
            }

            try
            {
                using (TodoAppEntities entities = new TodoAppEntities())
                {
                    entities.Todos.Add(todo);
                    entities.SaveChanges();
                    return(Ok(todo));
                }
            } catch (Exception ex)
            {
                return(Content(HttpStatusCode.BadRequest, ex));
            }
        }
示例#2
0
        public IHttpActionResult DeleteTodo(int id)
        {
            string method = "DELETE";

            TodoDTO todoDto = new TodoDTO();

            todoDto.id = id;

            if (!_todoBLL.ValidateTodo(todoDto, method))
            {
                return(BadRequest());
            }

            try
            {
                using (TodoAppEntities entities = new TodoAppEntities())
                {
                    var entity = entities.Todos.FirstOrDefault(todo => todo.id == id);

                    if (entity == null)
                    {
                        return(Content(HttpStatusCode.NotFound, "Todo not found"));
                    }

                    entities.Todos.Remove(entity);
                    entities.SaveChanges();
                    return(Ok(entity));
                }
            } catch (Exception ex)
            {
                return(Content(HttpStatusCode.BadRequest, ex));
            }
        }
示例#3
0
        public IHttpActionResult UpdateTodo(int id, [FromBody] Todo todo)
        {
            string method = "PUT";

            TodoDTO todoDto = new TodoDTO();

            todoDto.id        = id;
            todoDto.todo_text = todo.todo_text;
            todoDto.completed = todo.completed;

            if (!_todoBLL.ValidateTodo(todoDto, method))
            {
                return(BadRequest());
            }

            try
            {
                // everything below is DAL if else
                using (TodoAppEntities entities = new TodoAppEntities())
                {
                    var entity = entities.Todos.FirstOrDefault(tod => tod.id == id);

                    if (entity == null)
                    {
                        return(Content(HttpStatusCode.NotFound, "Todo not found"));
                    }

                    if (todo.todo_text != null)
                    {
                        entity.todo_text = todo.todo_text;
                    }


                    if (todo.completed == true)
                    {
                        entity.completed    = todo.completed;
                        entity.completed_at = DateTime.Now;
                    }
                    else
                    {
                        entity.completed    = false;
                        entity.completed_at = null;
                    }

                    entities.SaveChanges();
                    return(Ok(entity));
                }
            } catch (Exception e)
            {
                return(Content(HttpStatusCode.BadRequest, e));
            }
        }
示例#4
0
        public IHttpActionResult GetOneTodo(int id)
        {
            string method = "GET";

            TodoDTO todoDto = new TodoDTO();

            todoDto.id = id;

            if (!_todoBLL.ValidateTodo(todoDto, method))
            {
                return(BadRequest());
            }

            using (TodoAppEntities entities = new TodoAppEntities())
            {
                var entity = entities.Todos.FirstOrDefault(todo => todo.id == id);
                if (entity == null)
                {
                    return(Content(HttpStatusCode.NotFound, "Todo not found"));
                }
                return(Ok(entity));
            }
        }
示例#5
0
 public LoginController()
 {
     db = new TodoAppEntities();
 }
        public void NotifySend()
        {
            TodoAppEntities db = new TodoAppEntities();

            var reminders = db.Reminders.ToList();

            if (reminders.Count > 0)
            {
                foreach (var item in reminders)
                {
                    if (item.IsSend == false)
                    {
                        var date = DateTime.Parse(item.Date, new CultureInfo("en-US", true));

                        if (date.Date == DateTime.Today)
                        {
                            var    user     = db.Users.Where(x => x.ID == item.UserID).FirstOrDefault();
                            var    task     = db.Tasks.Where(x => x.ID == item.TaskID).FirstOrDefault();
                            string taskDesc = "";
                            if (task != null)
                            {
                                taskDesc = task.Description;
                            }
                            else
                            {
                                taskDesc = "";
                            }
                            if (user != null)
                            {
                                // NotificationType = 1 Mail
                                if (item.NotificationType == 1)
                                {
                                    try
                                    {
                                        SmtpClient sc = new SmtpClient();
                                        sc.Port        = 587;
                                        sc.Host        = "smtp.gmail.com";
                                        sc.EnableSsl   = true;
                                        sc.Credentials = new NetworkCredential("*****@*****.**", "***");
                                        MailMessage mail = new MailMessage();
                                        mail.From = new MailAddress("*****@*****.**", "Task Reminder");
                                        mail.To.Add(user.Mail);
                                        mail.Subject    = "Task Reminder";
                                        mail.IsBodyHtml = true;
                                        mail.Body       = string.Format("Do not forget this task! Just do it. <br/> {0}", taskDesc);
                                        sc.Send(mail);
                                        item.IsSend = true;
                                        db.SaveChanges();
                                    }
                                    catch (Exception e)
                                    {
                                    }
                                }
                                else if (item.NotificationType == 2)
                                {
                                    //SMS LOGIC
                                }
                            }
                        }
                    }
                }
            }
        }
 public TasksController()
 {
     db = new TodoAppEntities();
 }
示例#8
0
 public IEnumerable <Todo> GetAllTodos()
 {
     using (TodoAppEntities entities = new TodoAppEntities()) {
         return(entities.Todos.ToList());
     }
 }