public JsonResult Add(TaskVM task) { if (!String.IsNullOrWhiteSpace(task.Description)) { Task t = new Task(); t.ID = Guid.NewGuid(); t.Description = task.Description; t.DashboardID = task.DashboardID; t.CreatedDate = DateTime.Parse(DateTime.Now.ToShortDateString()); db.Tasks.Add(t); var result = db.SaveChanges(); if (result > 0) { Log.Debug("[TODOAPP]: Task creatad " + t.Description); return(JsonSuccess(t, "Task created!")); } else { Log.Error("[TODOAPP]: Task can't creatad"); return(JsonError("Task can't added!")); } } else { Log.Error("[TODOAPP]: Task description empty error"); return(JsonError("Task can't added!")); } }
public JsonResult Add(DashboardVM dashboard) { if (!String.IsNullOrWhiteSpace(dashboard.Name)) { Dashboard d = new Dashboard(); d.ID = Guid.NewGuid(); d.Name = dashboard.Name; d.CreatedDate = DateTime.Parse(DateTime.Now.ToShortDateString()); db.Dashboards.Add(d); var result = db.SaveChanges(); if (result > 0) { Log.Debug("[TODOAPP]: New dashboard created" + d.Name); return(JsonSuccess(d, "Dashboard created!")); } else { Log.Error("[TODOAPP]: Dashboard error(check db)"); return(JsonError("Dashboard can't added!")); } } else { Log.Error("[TODOAPP]: Dashboard name empty error"); return(JsonError("Dashboard can't added!")); } }
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)); } }
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)); } }
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)); } }
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 } } } } } } }