Exemple #1
0
        /// <summary>
        /// Get Checkpoint by id
        /// </summary>
        /// <param name="id">Checkpoint id</param>
        /// <returns>Checkpoint json view model</returns>
        public IHttpActionResult Get(int id)
        {
            try
            {
                // get
                log.Debug("_checkpointService.GetCheckpoint - checkpointId: " + id + " ");

                var checkpoint = new CheckpointViewModel(_checkpointService.GetCheckpoint(id));

                log.Debug("_checkpointService.GetCheckpoint - " + CheckpointViewModel.FormatCheckpointViewModel(checkpoint));

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

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

                throw;
            }
        }
Exemple #2
0
        private CheckpointDTO Create(CheckpointViewModel viewModel)
        {
            try
            {
                log.Debug(CheckpointViewModel.FormatCheckpointViewModel(viewModel));

                CheckpointDTO checkpoint = new CheckpointDTO();

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

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

                // add
                log.Debug("_checkpointService.AddCheckpoint - " + CheckpointDTO.FormatCheckpointDTO(checkpoint));

                int id = _checkpointService.AddCheckpoint(checkpoint);

                checkpoint.CheckpointId = id;

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

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

                throw;
            }
        }
Exemple #3
0
        private CheckpointDTO Update(CheckpointViewModel viewModel)
        {
            try
            {
                log.Debug(CheckpointViewModel.FormatCheckpointViewModel(viewModel));

                // get
                log.Debug("_checkpointService.GetCheckpoint - checkpointId: " + viewModel.CheckpointId + " ");

                var existingCheckpoint = _checkpointService.GetCheckpoint(viewModel.CheckpointId);

                log.Debug("_checkpointService.GetCheckpoint - " + CheckpointDTO.FormatCheckpointDTO(existingCheckpoint));

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

                    // update
                    log.Debug("_checkpointService.UpdateCheckpoint - " + CheckpointDTO.FormatCheckpointDTO(existingCheckpoint));

                    _checkpointService.UpdateCheckpoint(existingCheckpoint);

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

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

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

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

                        if (viewModel.CheckpointId > 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;
            }
        }