コード例 #1
0
        public async Task <JsonResult> UpdateRandomIdea(RandomIdea randomIdea)
        {
            var error = randomIdea.VerifyContent();

            if (error.Length != 0)
            {
                return(new JsonResult(new JsonResponse {
                    Result = SharedEnums.RequestResults.Failed, Data = error
                }));
            }

            var saveResult = await _randomIdeaService.UpdateRandomIdea(randomIdea);

            return(!saveResult.HasValue || !saveResult.Value
                ? new JsonResult(new JsonResponse {
                Result = SharedEnums.RequestResults.Failed, Message = "An issue happened while updating data."
            })
                : new JsonResult(new JsonResponse {
                Result = SharedEnums.RequestResults.Success
            }));
        }
コード例 #2
0
        public async Task <bool?> UpdateRandomIdea(RandomIdea randomIdea)
        {
            try {
                _dbContext.RandomIdeas.Update(randomIdea);
                var result = await _dbContext.SaveChangesAsync();

                return(result != 0);
            }
            catch (DbUpdateException e) {
                await _coreLogService.InsertRoutinizeCoreLog(new RoutinizeCoreLog {
                    Location            = $"{ nameof(RandomIdeaService) }.{ nameof(UpdateRandomIdea) }",
                    Caller              = $"{ new StackTrace().GetFrame(4)?.GetMethod()?.DeclaringType?.FullName }",
                    BriefInformation    = nameof(DbUpdateException),
                    DetailedInformation = $"Error while updating entry to RandomIdeas.\n\n{ e.StackTrace }",
                    ParamData           = $"{ nameof(randomIdea) } = { JsonConvert.SerializeObject(randomIdea) }",
                    Severity            = SharedEnums.LogSeverity.High.GetEnumValue()
                });

                return(null);
            }
        }
コード例 #3
0
        public async Task <JsonResult> AddNewRandomIdea([FromHeader] int userId, [FromBody] RandomIdea randomIdea)
        {
            var error = randomIdea.VerifyContent();

            if (error.Length != 0)
            {
                return(new JsonResult(new JsonResponse {
                    Result = SharedEnums.RequestResults.Failed, Data = error
                }));
            }

            randomIdea.UserId = userId;

            var saveResult = await _randomIdeaService.InsertNewRandomIdea(randomIdea);

            return(!saveResult.HasValue || saveResult.Value < 1
                ? new JsonResult(new JsonResponse {
                Result = SharedEnums.RequestResults.Failed, Message = "An issue happened while saving data."
            })
                : new JsonResult(new JsonResponse {
                Result = SharedEnums.RequestResults.Success, Data = saveResult.Value
            }));
        }