public AjaxResponse Command(TaskPostRequest model) { Core.Domain.Task task = null; if (model.Id.IsEmpty()) { var card = _cardService.GetCard(model.CardId); task = new Core.Domain.Task { Description = model.Description }; card.AddTask(task); _cardService.SaveCard(card); _taskService.Update(task); } else { task = _taskService.Retreive(model.Id); task.Description = model.Description; _taskService.Update(task); } return new AjaxResponse {Success = true, Item = Mapper.DynamicMap<TaskDTO>(task)}; }
/// <summary> /// Delete a Task /// </summary> /// <param name="Task">Task</param> public virtual void DeleteTask(Core.Domain.Task Task) { if (Task == null) { throw new ArgumentNullException(nameof(Task)); } _taskRepository.Delete(Task); }
/// <summary> /// Updates the task /// </summary> /// <param name="task">Customer</param> public virtual void UpdateCustomer(Core.Domain.Task task) { if (task == null) { throw new ArgumentNullException(nameof(task)); } _taskRepository.Update(task); }
/// <summary> /// Insert a customer /// </summary> /// <param name="customer">Customer</param> public virtual void InsertTask(Core.Domain.Task Task) { if (Task == null) { throw new ArgumentNullException(nameof(Task)); } Task.CreatedDate = DateTime.Now; _taskRepository.Insert(Task); }
public async Task <Result> Put(Core.Domain.Task task) { Result result = new Result(); try { if (task == null) { result.Exception.Add($"Task cannot be null"); result.StatusCode = HttpStatusCode.BadRequest; } var oldTask = await GetTaskById(task.Id); if (oldTask == null) { result.Exception.Add($"Cannot find task with id: {task.Id}"); result.StatusCode = HttpStatusCode.NotFound; } if (string.IsNullOrEmpty(task.Title)) { result.Exception.Add("Title cannot be empty"); result.StatusCode = HttpStatusCode.BadRequest; } if (string.IsNullOrEmpty(task.Description)) { result.Exception.Add("Description cannot be empty"); result.StatusCode = HttpStatusCode.BadRequest; } if (task.ExpectedEndDate.Ticks < DateTime.UtcNow.Ticks) { result.Exception.Add("End Date cannot be lower than current date"); result.StatusCode = HttpStatusCode.BadRequest; } if (result.Exception.Any()) { return(result); } _context.Tasks.Update(task); _context.Entry(task).State = EntityState.Modified; await _context.SaveChangesAsync(); result.ResultMessage = "Updated correctly"; result.StatusCode = HttpStatusCode.OK; } catch (Exception ex) { result.Exception.Add(ex.Message); result.StatusCode = HttpStatusCode.BadRequest; } return(result); }
public async Task CreateAsync(Core.Domain.Task task) { try { var taskDbModel = _mapper.Map <Core.Domain.Task, TaskDbModel>(task); _context.Task.Add(taskDbModel); await _context.SaveChangesAsync(); } catch (Exception ex) { Debug.Print($"Błąd zapisu nowego zadania do bazy danych {ex}"); } }
public async Task <Result> Post(Core.Domain.Task task) { Result result = new Result(); try { if (string.IsNullOrEmpty(task.Title)) { result.Exception.Add("Title cannot be empty"); result.StatusCode = HttpStatusCode.BadRequest; } if (string.IsNullOrEmpty(task.Description)) { result.Exception.Add("Description cannot be empty"); result.StatusCode = HttpStatusCode.BadRequest; } if (task.ExpectedEndDate.Ticks < DateTime.UtcNow.Ticks) { result.Exception.Add("End Date cannot be lower than current date"); result.StatusCode = HttpStatusCode.BadRequest; } if (result.Exception.Any()) { return(result); } await _context.Tasks.AddAsync(task); await _context.SaveChangesAsync(); result.ResultMessage = "Saved correctly"; result.StatusCode = HttpStatusCode.Created; } catch (Exception ex) { result.Exception.Add(ex.Message); result.StatusCode = HttpStatusCode.BadRequest; } return(result); }
public async Task AddAsync(string title, string description, DateTime term, Guid owner) { var task = new Core.Domain.Task(title, description, term, owner); await _taskRepository.CreateAsync(task); }