Example #1
0
        public async Task <JsonResult> CreateGroup([FromRoute] string groupType, [FromBody] ContentGroup contentGroup)
        {
            var errors = contentGroup.VerifyContentGroupData();

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

            contentGroup.GroupOfType = groupType;
            var result = await _groupService.InsertNewContentGroup(contentGroup);

            return(!result.HasValue || result.Value < 1
                ? new JsonResult(new JsonResponse {
                Result = SharedEnums.RequestResults.Failed, Message = "An issue happened while updating data."
            })
                : new JsonResult(new JsonResponse {
                Result = SharedEnums.RequestResults.Success, Data = result.Value
            }));
        }
Example #2
0
        public async Task <JsonResult> UpdateGroup([FromRoute] int updatedByUserId, [FromBody] ContentGroup contentGroup)
        {
            var errors = contentGroup.VerifyContentGroupData(true);

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

            var shouldUpdateTodoGroup = await IsContentGroupAndUserAssociated(updatedByUserId, contentGroup, SharedEnums.Permissions.Edit);

            if (!shouldUpdateTodoGroup.HasValue)
            {
                return(new JsonResult(new JsonResponse {
                    Result = SharedEnums.RequestResults.Failed, Message = "An issue happened while getting data."
                }));
            }
            if (!shouldUpdateTodoGroup.Value)
            {
                return(new JsonResult(new JsonResponse {
                    Result = SharedEnums.RequestResults.Failed, Message = "You are not authorized for this action."
                }));
            }

            var result = await _groupService.UpdateContentGroup(contentGroup);

            return(result
                ? new JsonResult(new JsonResponse {
                Result = SharedEnums.RequestResults.Success
            })
                : new JsonResult(new JsonResponse {
                Result = SharedEnums.RequestResults.Failed, Message = "An issue happened while updating data."
            }));
        }