public IActionResult UpdateGroup(int id, [FromBody] GroupForUpdateDto groupDto)
        {
            if (groupDto == null)
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var groupEntity = _registrationRepository.GetGroup(id, includeSubgroups: false);

            if (groupEntity == null)
            {
                return(NotFound());
            }

            Mapper.Map(groupDto, groupEntity);

            if (!_registrationRepository.Save())
            {
                return(StatusCode(500, "A problem happened while handling your request."));
            }

            return(NoContent());
        }
Exemple #2
0
        public JsonResult UpdateAccount([FromBody] GroupForUpdateDto group)
        {
            string functionName = System.Reflection.MethodBase.GetCurrentMethod().Name;

            try
            {
                //Check id group exist in the database
                if (!_groupRepository.GroupExist(group.groupId))
                {
                    Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.groupNotFound));
                    return(Json(MessageResult.GetMessage(MessageType.GROUP_NOT_FOUND)));
                }

                //Check value enter from the form
                if (group == null)
                {
                    Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.notInformationGroup));
                    return(Json(MessageResult.GetMessage(MessageType.NOT_INFORMATION_GROUP)));
                }

                if (!ModelState.IsValid)
                {
                    Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.notFound));
                    return(Json(MessageResult.GetMessage(MessageType.NOT_FOUND)));
                }

                //This is get all information of group
                var groupEntity = _groupRepository.GetGroupById(group.groupId);

                if (groupEntity == null)
                {
                    Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.groupNotFound));
                    return(Json(MessageResult.GetMessage(MessageType.GROUP_NOT_FOUND)));
                }

                //Map data enter from the form to group entity
                Mapper.Map(group, groupEntity);

                if (!_groupRepository.Save())
                {
                    Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.badRequest));
                    return(Json(MessageResult.GetMessage(MessageType.BAD_REQUEST)));
                }

                Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.groupUpdated));
                return(Json(MessageResult.GetMessage(MessageType.GROUP_UPDATED)));
            }
            catch (Exception ex)
            {
                Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(ex.Message));
                return(Json(MessageResult.ShowServerError(ex.Message)));
            }
        }