Exemplo n.º 1
0
        public UserViewModel SaveUser(UserViewModel model, CrudOperation crudOperation)
        {
            UserDto    user       = new UserDto();
            CrudStatus crudStatus = CrudStatusMapper.MapToEnum(crudOperation);

            user.MapToDto(model);

            Response <UserDto> response = EntityFactory.UserManager.SaveUser(user, crudStatus);

            if (response.HasErrors)
            {
                ModelStateException modelStateException = new ModelStateException();
                response.ErrorMessages.ToList().ForEach(item => modelStateException.ModelErrors.Add(new ModelStateError()
                {
                    FieldName = item.FieldName, Message = item.Message
                }));

                throw modelStateException;
            }

            return(response.Model.MapFromDto());
        }
Exemplo n.º 2
0
        public PolicyViewModel SavePolicy(PolicyViewModel model)
        {
            PolicyDto  policy     = new PolicyDto();
            CrudStatus crudStatus = CrudStatusMapper.MapToEnum(model.CrudOperation);

            policy.MapToDto(model);

            Response <PolicyDto> response = EntityFactory.PolicyManager.SavePolicy(policy, crudStatus);

            if (response.HasErrors)
            {
                ModelStateException modelStateException = new ModelStateException();
                response.ErrorMessages.ToList().ForEach(item => modelStateException.ModelErrors.Add(new ModelStateError()
                {
                    FieldName = item.FieldName, Message = item.Message
                }));

                throw modelStateException;
            }

            return(model.CrudOperation == CrudOperation.DELETE ? new PolicyViewModel() : response.Model.MapFromDto());
        }