Пример #1
0
        /// <summary>
        /// Get Task by id
        /// </summary>
        /// <param name="id">Task id</param>
        /// <returns>Task json view model</returns>
        public IHttpActionResult Get(int id)
        {
            try
            {
                // get
                log.Debug("_taskService.GetTask - taskId: " + id + " ");

                var task = new TaskViewModel(_taskService.GetTask(id));

                log.Debug("_taskService.GetTask - " + TaskViewModel.FormatTaskViewModel(task));

                log.Debug("result: 'success'");

                //return Json(task, JsonRequestBehavior.AllowGet);
                //return Content(JsonConvert.SerializeObject(task), "application/json");
                //return task;
                //return JsonConvert.SerializeObject(task);
                return(Ok(task));
            }
            catch (Exception e)
            {
                // error
                log.Error(e.ToString());

                throw;
            }
        }
Пример #2
0
        private TaskDTO Create(TaskViewModel viewModel)
        {
            try
            {
                log.Debug(TaskViewModel.FormatTaskViewModel(viewModel));

                TaskDTO task = new TaskDTO();

                // copy values
                viewModel.UpdateDTO(task, null); //RequestContext.Principal.Identity.GetUserId());

                // audit
                task.CreateBy = null; //RequestContext.Principal.Identity.GetUserId();
                task.CreateOn = DateTime.UtcNow;

                // add
                log.Debug("_taskService.AddTask - " + TaskDTO.FormatTaskDTO(task));

                int id = _taskService.AddTask(task);

                task.TaskId = id;

                log.Debug("result: 'success', id: " + id);

                return(task);
            }
            catch (Exception e)
            {
                // error
                log.Error(e.ToString());

                throw;
            }
        }
Пример #3
0
        private TaskDTO Update(TaskViewModel viewModel)
        {
            try
            {
                log.Debug(TaskViewModel.FormatTaskViewModel(viewModel));

                // get
                log.Debug("_taskService.GetTask - taskId: " + viewModel.TaskId + " ");

                var existingTask = _taskService.GetTask(viewModel.TaskId);

                log.Debug("_taskService.GetTask - " + TaskDTO.FormatTaskDTO(existingTask));

                if (existingTask != null)
                {
                    // copy values
                    viewModel.UpdateDTO(existingTask, null); //RequestContext.Principal.Identity.GetUserId());

                    // update
                    log.Debug("_taskService.UpdateTask - " + TaskDTO.FormatTaskDTO(existingTask));

                    _taskService.UpdateTask(existingTask);

                    log.Debug("result: 'success'");
                }
                else
                {
                    log.Error("existingTask: null, TaskId: " + viewModel.TaskId);
                }

                return(existingTask);
            }
            catch (Exception e)
            {
                // error
                log.Error(e.ToString());

                throw;
            }
        }
Пример #4
0
        //[ValidateAntiForgeryToken]
        /// <summary>
        /// Save a list of Task
        /// </summary>
        /// <param name="viewModels">Task view models</param>
        /// <param name="id">(not used)</param>
        /// <returns>true if the operation is successfull</returns>
        public IHttpActionResult SaveList(TaskViewModel[] viewModels, int?id)
        {
            try
            {
                log.Debug("SaveList");

                if (viewModels != null)
                {
                    // save list
                    foreach (TaskViewModel viewModel in viewModels)
                    {
                        log.Debug(TaskViewModel.FormatTaskViewModel(viewModel));

                        if (viewModel.TaskId > 0)
                        {
                            var t = Update(viewModel);
                        }
                        else
                        {
                            var t = Create(viewModel);
                        }
                    }
                }
                else
                {
                    log.Error("viewModels: null");
                }

                //return Json(true);
                //return JsonConvert.SerializeObject(true);
                return(Ok(true));
            }
            catch (Exception e)
            {
                // error
                log.Error(e.ToString());

                throw;
            }
        }