Example #1
0
        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)};
        }
Example #2
0
        /// <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);
        }
Example #3
0
        /// <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);
        }
Example #4
0
        /// <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);
        }
Example #5
0
        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);
        }
Example #6
0
 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}");
     }
 }
Example #7
0
        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);
        }
Example #8
0
 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);
 }