public async Task <IActionResult> CreatePlace(PlaceCreateRequest request)
        {
            //Creazione modello richiesto da admin
            var model = new Place
            {
                Name          = request.Name,
                Holder        = request.Holder,
                Phone         = request.Phone,
                Email         = request.Email,
                Address       = request.Address,
                City          = request.City,
                Region        = request.Region,
                PostalZipCode = request.PostalZipCode,
                Country       = request.Country
            };

            //Invocazione del service layer
            var validations = await BasicLayer.CreatePlace(model, PlatformUtils.GetIdentityUserId(User));

            if (validations.Count > 0)
            {
                return(BadRequest(validations));
            }

            //Return contract
            return(Ok(ContractUtils.GenerateContract(model)));
        }
Example #2
0
        public async Task <IActionResult> UpdatePassword(ChangePasswordRequest request)
        {
            //user identifier
            var userId = PlatformUtils.GetIdentityUserId(User);

            var user = AuthorizationLayer.GetUserById(userId);

            //Tento il signin ed ottengo l'utente se è completato
            var result = await AuthorizationLayer.SignIn(user.Username, request.OldPassword);

            //Se non ho utente, unauthorized
            if (result == null)
            {
                return(Unauthorized());
            }

            // recupero il profilo
            var validations = AuthorizationLayer.UpdateUserPassword(result, request.Password);

            //controllo risultato
            if (validations.Count > 0)
            {
                return(BadRequest(validations));
            }

            //Se è tutto ok, serializzo e restituisco
            return(Ok(new StringResponse {
                Value = request.Password
            }));
        }
Example #3
0
        public async Task <IActionResult> DeleteUserROle(UserRoleRequest request)
        {
            //Recupero l'elemento dal business layer
            var entity = AuthorizationLayer.GetUserRole(request.UserRoleId);

            //Se l'utente non hai i permessi non posso rimuovere entità con userId nullo
            if (entity == null)
            {
                return(NotFound());
            }

            //Invocazione del service layer
            var validations = await AuthorizationLayer.DeleteUserRole(entity, PlatformUtils.GetIdentityUserId(User));

            if (validations.Count > 0)
            {
                return(BadRequest(validations));
            }

            var userRoles = AuthorizationLayer.FetchUserRole(entity.RoleId);

            var userIds = userRoles.Select(x => x.UserId).ToList();

            var users = BasicLayer.FetchShootersByIds(userIds);

            //Return contract
            return(Ok(userRoles.As(x => ContractUtils.GenerateContract(x, users?.FirstOrDefault(s => s.Id == x.UserId)))));
        }
        public async Task <IActionResult> CreateShooterTeamPayment(ShooterTeamPaymentCreateRequest request)
        {
            //Creazione modello richiesto da admin
            var model = new ShooterTeamPayment
            {
                ShooterId        = request.ShooterId,
                TeamId           = request.TeamId,
                Amount           = request.Amount,
                Reason           = request.Reason,
                PaymentDateTime  = request.PaymentDateTime,
                ExpireDateTime   = request.ExpireDateTime,
                NotifyExpiration = request.NotifyExpiration
            };

            //Invocazione del service layer
            var validations = await BasicLayer.CreateShooterTeamPayment(model, PlatformUtils.GetIdentityUserId(User));

            if (validations.Count > 0)
            {
                return(BadRequest(validations));
            }

            //Return contract
            return(Ok(ContractUtils.GenerateContract(model)));
        }
Example #5
0
        public async Task <IActionResult> UpdateRole(RoleUpdateRequest request)
        {
            //Recupero l'elemento dal business layer
            var entity = AuthorizationLayer.GetRole(request.RoleId);

            //modifica solo se admin o se utente richiedente è lo stesso che ha creato
            if (entity == null)
            {
                return(NotFound());
            }

            //Aggiornamento dell'entità
            entity.Name        = request.Name;
            entity.Description = request.Description;

            //Salvataggio
            var validations = await AuthorizationLayer.UpdateRole(entity, PlatformUtils.GetIdentityUserId(User));

            if (validations.Count > 0)
            {
                return(BadRequest(validations));
            }


            var permissions = AuthorizationLayer.FetchPermissionsOnRole(entity.Id);

            //Confermo
            return(Ok(ContractUtils.GenerateContract(entity, permissions)));
        }
Example #6
0
        public async Task <IActionResult> CallShooter(CallShooterRequest request)
        {
            // For a real application, generate your own
            var currentUserId = PlatformUtils.GetIdentityUserId(User);
            var existingUser  = AuthorizationLayer.GetUserById(currentUserId);

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

            var subscriptions = BasicLayer.FetchNotificationSubscriptionsByUserId(request.ShooterId);

            var vapidDetails = new VapidDetails($"mailto:{_vapidUser}", _publicKey, _privateKey);


            var pushSubscriptions = subscriptions.Select(x => new PushSubscription(x.Url, x.P256dh, x.Auth)).ToList();
            var webPushClient     = new WebPushClient();

            try
            {
                var message = string.Empty;
                switch ((int)request.Context)
                {
                case (int)CallShooterContextEnum.MatchDirector:
                    var userStage = BasicLayer.GetSOStage(request.MatchId, existingUser.Id);
                    message = $"{existingUser.FirstName} {existingUser.LastName} ti sta cercando allo stage {userStage.Index}:{userStage.Name}!";
                    break;

                default:
                    message = $"{existingUser.FirstName} {existingUser.LastName} ti sta cercando!";
                    break;
                }
                var payload = JsonSerializer.Serialize(new
                {
                    message,
                    url = string.Empty,
                });
                if (pushSubscriptions.Count == 0)
                {
                    return(Ok(new OkResponse {
                        Status = false, Errors = new List <string> {
                            "NoSubscriptions"
                        }
                    }));
                }
                var tasks = pushSubscriptions.Select(pushSubscription => webPushClient.SendNotificationAsync(pushSubscription, payload, vapidDetails)).ToList();
                await Task.WhenAll(tasks);

                return(Ok(new OkResponse()
                {
                    Status = true
                }));
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine("Error sending push notification: " + ex.Message);
                return(Ok(ex));
            }
        }
        public async Task <IActionResult> UpdateShooterTeamPayment([EntityId] ShooterTeamPaymentUpdateRequest request)
        {
            //Recupero l'elemento dal business layer
            var entity = BasicLayer.GetShooterTeamPayment(request.ShooterTeamPaymentId);

            //modifica solo se admin o se utente richiedente è lo stesso che ha creato
            if (entity == null)
            {
                return(NotFound());
            }

            //Aggiornamento dell'entità
            entity.TeamId           = request.TeamId;
            entity.ShooterId        = request.ShooterId;
            entity.Amount           = request.Amount;
            entity.Reason           = request.Reason;
            entity.PaymentDateTime  = request.PaymentDateTime;
            entity.ExpireDateTime   = request.ExpireDateTime;
            entity.NotifyExpiration = request.NotifyExpiration;

            //Salvataggio
            var validations = await BasicLayer.UpdateShooterTeamPayment(entity, PlatformUtils.GetIdentityUserId(User));

            if (validations.Count > 0)
            {
                return(BadRequest(validations));
            }

            //Confermo
            return(Ok(ContractUtils.GenerateContract(entity)));
        }
Example #8
0
        public Task <IActionResult> CreateNotificationSubscription(NotificationSubscriptionCreateRequest request)
        {
            var currentUserId = PlatformUtils.GetIdentityUserId(User);
            var existingUser  = AuthorizationLayer.GetUserById(currentUserId);

            if (existingUser == null)
            {
                return(Task.FromResult <IActionResult>(NotFound()));
            }

            var model = new NotificationSubscription
            {
                UserId = existingUser.Id,
                Url    = request.Url,
                P256dh = request.P256dh,
                Auth   = request.Auth
            };
            //Invocazione del service layer
            var validations = BasicLayer.CreateNotificationSubscription(model);

            if (validations.Count > 0)
            {
                return(BadRequestTask(validations));
            }

            //Return contract
            return(Reply(new OkResponse {
                Status = true
            }));
        }
        public async Task <IActionResult> UpdateTeam([EntityId] TeamUpdateRequest request)
        {
            //Recupero l'elemento dal business layer
            var entity = BasicLayer.GetTeam(request.TeamId);

            //modifica solo se admin o se utente richiedente è lo stesso che ha creato
            if (entity == null)
            {
                return(NotFound());
            }

            //Aggiornamento dell'entità
            entity.Name = request.Name;

            //Salvataggio
            var validations = await BasicLayer.UpdateTeam(entity, PlatformUtils.GetIdentityUserId(User));

            if (validations.Count > 0)
            {
                return(BadRequest(validations));
            }

            //Confermo
            return(Ok(ContractUtils.GenerateContract(entity)));
        }
        public async Task <IActionResult> UpdatePlace([EntityId] PlaceUpdateRequest request)
        {
            //Recupero l'elemento dal business layer
            var entity = BasicLayer.GetPlace(request.PlaceId);

            //modifica solo se admin o se utente richiedente è lo stesso che ha creato
            if (entity == null)
            {
                return(NotFound());
            }

            //Aggiornamento dell'entità
            entity.Name          = request.Name;
            entity.Holder        = request.Holder;
            entity.Phone         = request.Phone;
            entity.Email         = request.Email;
            entity.Address       = request.Address;
            entity.City          = request.City;
            entity.Region        = request.Region;
            entity.PostalZipCode = request.PostalZipCode;
            entity.Country       = request.Country;

            //Salvataggio
            var validations = await BasicLayer.UpdatePlace(entity, PlatformUtils.GetIdentityUserId(User));

            if (validations.Count > 0)
            {
                return(BadRequest(validations));
            }

            //Confermo
            return(Ok(ContractUtils.GenerateContract(entity)));
        }
        public async Task <IActionResult> CreateMatch(MatchCreateRequest request)
        {
            //Creazione modello richiesto da admin
            var model = new Match
            {
                Name = request.Name,
                MatchDateTimeStart   = request.MatchDateTimeStart,
                MatchDateTimeEnd     = request.MatchDateTimeEnd,
                AssociationId        = request.AssociationId,
                PlaceId              = request.PlaceId,
                OpenMatch            = request.OpenMatch,
                UnifyClassifications = request.UnifyClassifications,
                Cost           = request.Cost,
                PaymentDetails = request.PaymentDetails
            };

            //Invocazione del service layer
            var validations = await BasicLayer.CreateMatch(model, PlatformUtils.GetIdentityUserId(User));

            if (validations.Count > 0)
            {
                return(BadRequest(validations));
            }

            var association = BasicLayer.GetAssociation(model.AssociationId);
            var place       = BasicLayer.GetPlace(model.PlaceId);

            //Return contract
            return(Ok(ContractUtils.GenerateContract(model, association, place)));
        }
        public async Task <IActionResult> CreateShooterAssociationInfo(ShooterAssociationInfoCreateRequest request)
        {
            var(validations, shooter, association) = CheckRequest(request.ShooterId, request.AssociationId, request.Categories);
            if (validations.Count > 0)
            {
                return(BadRequest(validations));
            }

            var entity = new ShooterAssociationInfo
            {
                ShooterId        = request.ShooterId,
                AssociationId    = request.AssociationId,
                CardNumber       = request.CardNumber,
                SafetyOfficier   = request.SafetyOfficier,
                RegistrationDate = request.RegistrationDate,
                Categories       = request.Categories
            };

            //Invocazione del service layer
            validations = await BasicLayer.CreateShooterAssociationInfo(entity, PlatformUtils.GetIdentityUserId(User));

            if (validations.Count > 0)
            {
                return(BadRequest(validations));
            }

            //Return contract
            return(Ok(ContractUtils.GenerateContract(entity, association, shooter)));
        }
        public async Task <IActionResult> UpdateShooterAssociationInfo(ShooterAssociationInfoUpdateRequest request)
        {
            var entity = this.BasicLayer.GetShooterAssociationInfo(request.ShooterAssociationInfoId);

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

            var(validations, shooter, association) = CheckRequest(request.ShooterId, request.AssociationId, request.Categories);
            if (validations.Count > 0)
            {
                return(BadRequest(validations));
            }

            entity.ShooterId        = request.ShooterId;
            entity.AssociationId    = request.AssociationId;
            entity.CardNumber       = request.CardNumber;
            entity.SafetyOfficier   = request.SafetyOfficier;
            entity.Categories       = request.Categories;
            entity.RegistrationDate = request.RegistrationDate;


            //Invocazione del service layer
            validations = await BasicLayer.UpdateShooterAssociationInfo(entity, PlatformUtils.GetIdentityUserId(User));

            if (validations.Count > 0)
            {
                return(BadRequest(validations));
            }

            //Return contract
            return(Ok(ContractUtils.GenerateContract(entity, association, shooter)));
        }
        public async Task <IActionResult> DeleteMatch([EntityId] MatchRequest request)
        {
            //Recupero l'elemento dal business layer
            var entity = BasicLayer.GetMatch(request.MatchId);

            //Se l'utente non hai i permessi non posso rimuovere entità con userId nullo
            if (entity == null)
            {
                return(NotFound());
            }

            //Invocazione del service layer
            var validations = await BasicLayer.DeleteMatch(entity, PlatformUtils.GetIdentityUserId(User));

            if (validations.Count > 0)
            {
                return(BadRequest(validations));
            }

            var association = BasicLayer.GetAssociation(entity.AssociationId);
            var place       = BasicLayer.GetPlace(entity.PlaceId);

            //Return contract
            return(Ok(ContractUtils.GenerateContract(entity, association, place)));
        }
Example #15
0
        public async Task <IActionResult> CreateShooter(ShooterCreateRequest request)
        {
            //Creazione modello richiesto da admin
            var model = new Shooter
            {
                FirstName                    = request.FirstName,
                LastName                     = request.LastName,
                BirthDate                    = request.BirthDate,
                Email                        = request.Email,
                Username                     = request.Username,
                FirearmsLicence              = request.FirearmsLicence,
                FirearmsLicenceExpireDate    = request.FirearmsLicenceExpireDate,
                FirearmsLicenceReleaseDate   = request.FirearmsLicenceReleaseDate,
                MedicalExaminationExpireDate = request.MedicalExaminationExpireDate,
                BirthLocation                = request.BirthLocation,
                Address                      = request.Address,
                City       = request.City,
                PostalCode = request.PostalCode,
                Province   = request.Province,
                Country    = request.Country,
                Phone      = request.Phone,
                FiscalCode = request.FiscalCode
            };

            //Invocazione del service layer
            var validations = await BasicLayer.CreateShooter(model, PlatformUtils.GetIdentityUserId(User));

            if (validations.Count > 0)
            {
                return(BadRequest(validations));
            }

            //Return contract
            return(Ok(ContractUtils.GenerateContract(model)));
        }
        public async Task <IActionResult> CreateAssociation(AssociationCreateRequest request)
        {
            //Creazione modello richiesto da admin
            var model = new Association
            {
                Name                      = request.Name,
                Classifications           = request.Classifications,
                Divisions                 = request.Divisions,
                Categories                = request.Categories,
                FirstPenaltyLabel         = request.FirstPenaltyLabel,
                HitOnNonThreatPointDown   = request.HitOnNonThreatPointDown,
                FirstProceduralPointDown  = request.FirstProceduralPointDown,
                SecondPenaltyLabel        = request.SecondPenaltyLabel,
                SecondProceduralPointDown = request.SecondProceduralPointDown,
                ThirdPenaltyLabel         = request.ThirdPenaltyLabel,
                ThirdProceduralPointDown  = request.ThirdProceduralPointDown,
                SoRoles                   = request.SoRoles
            };

            //Invocazione del service layer
            var validations = await BasicLayer.CreateAssociation(model, PlatformUtils.GetIdentityUserId(User));

            if (validations.Count > 0)
            {
                return(BadRequest(validations));
            }


            //Return contract
            return(Ok(ContractUtils.GenerateContract(model)));
        }
Example #17
0
        public IActionResult UpdateUserPassword(UserPasswordUpdateRequest request)
        {
            //User id corrente
            var userId = PlatformUtils.GetIdentityUserId(User);

            //modifica solo se admin o se sè stesso o è autorizzato
            if (request.UserId != userId)
            {
                return(Unauthorized());
            }

            //Recupero l'elemento dal business layer
            var entity = AuthorizationLayer.GetUserById(request.UserId);

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

            //Salvataggio
            var validations = AuthorizationLayer.UpdateUserPassword(entity, request.Password);

            if (validations.Count > 0)
            {
                return(BadRequest(validations));
            }

            //Confermo
            return(Ok(new BooleanResponse()
            {
                Value = true
            }));
        }
Example #18
0
        public IActionResult GetProfile()
        {
            var userId = PlatformUtils.GetIdentityUserId(User);

            var entity = AuthorizationLayer.GetUserById(userId);

            //verifico validità dell'entità
            if (entity == null)
            {
                return(NotFound());
            }

            //Serializzazione e conferma
            return(Ok(ContractUtils.GenerateContract(entity)));
        }
Example #19
0
        public async Task <IActionResult> CreateRole(RoleCreateRequest request)
        {
            //Creazione modello richiesto da admin
            var model = new Role
            {
                Name        = request.Name,
                Description = request.Description
            };

            //Invocazione del service layer
            var validations = await AuthorizationLayer.CreateRole(model, PlatformUtils.GetIdentityUserId(User));

            if (validations.Count > 0)
            {
                return(BadRequest(validations));
            }

            //Return contract
            return(Ok(ContractUtils.GenerateContract(model)));
        }
        public async Task <IActionResult> CreateTeam(TeamCreateRequest request)
        {
            //Creazione modello richiesto da admin
            var model = new Team
            {
                Name = request.Name
            };

            //Invocazione del service layer
            var validations = await BasicLayer.CreateTeam(model, PlatformUtils.GetIdentityUserId(User));

            if (validations.Count > 0)
            {
                return(BadRequest(validations));
            }


            //Return contract
            return(Ok(ContractUtils.GenerateContract(model)));
        }
Example #21
0
        public async Task <IActionResult> CreateUserRole(UserRoleCreateRequest request)
        {
            //Recupero l'elemento dal business layer
            var user = BasicLayer.GetShooter(request.UserId);

            if (user == null)
            {
                return(NotFound($"User with {request.UserId} not found"));
            }

            //Recupero l'elemento dal business layer
            var role = AuthorizationLayer.GetRole(request.RoleId);

            if (role == null)
            {
                return(NotFound($"Role with {request.RoleId} not found"));
            }

            var entity = new UserRole()
            {
                UserId   = user.Id,
                RoleId   = role.Id,
                EntityId = request.EntityId
            };
            //Invocazione del service layer
            var validations = await AuthorizationLayer.CreateUserRole(entity, PlatformUtils.GetIdentityUserId(User));

            if (validations.Count > 0)
            {
                return(BadRequest(validations));
            }

            var userRoles = AuthorizationLayer.FetchUserRole(role.Id);

            var userIds = userRoles.Select(x => x.UserId).ToList();

            var users = BasicLayer.FetchShootersByIds(userIds);

            //Return contract
            return(Ok(userRoles.As(x => ContractUtils.GenerateContract(x, users?.FirstOrDefault(s => s.Id == x.UserId)))));
        }
Example #22
0
        public async Task <IActionResult> UpdateShooter([EntityId] ShooterUpdateRequest request)
        {
            //Recupero l'elemento dal business layer
            var entity = BasicLayer.GetShooter(request.ShooterId);

            //modifica solo se admin o se utente richiedente è lo stesso che ha creato
            if (entity == null)
            {
                return(NotFound());
            }

            //Aggiornamento dell'entità
            entity.FirstName = request.FirstName;
            entity.LastName  = request.LastName;
            entity.BirthDate = request.BirthDate;
            entity.Email     = request.Email;
            entity.Username  = request.Username;
            entity.FirearmsLicenceExpireDate    = request.FirearmsLicenceExpireDate;
            entity.FirearmsLicence              = request.FirearmsLicence;
            entity.MedicalExaminationExpireDate = request.MedicalExaminationExpireDate;
            entity.BirthLocation = request.BirthLocation;
            entity.Address       = request.Address;
            entity.City          = request.City;
            entity.PostalCode    = request.PostalCode;
            entity.Province      = request.Province;
            entity.Country       = request.Country;
            entity.Phone         = request.Phone;
            entity.FiscalCode    = request.FiscalCode;

            //Salvataggio
            var validations = await BasicLayer.UpdateShooter(entity, PlatformUtils.GetIdentityUserId(User));

            if (validations.Count > 0)
            {
                return(BadRequest(validations));
            }

            //Confermo
            return(Ok(ContractUtils.GenerateContract(entity)));
        }
Example #23
0
        public async Task <IActionResult> DeleteShooter([EntityId] ShooterRequest request)
        {
            //Recupero l'elemento dal business layer
            var entity = BasicLayer.GetShooter(request.ShooterId);

            //Se l'utente non hai i permessi non posso rimuovere entità con userId nullo
            if (entity == null)
            {
                return(NotFound());
            }

            //Invocazione del service layer
            var validations = await BasicLayer.DeleteShooter(entity, PlatformUtils.GetIdentityUserId(User));

            if (validations.Count > 0)
            {
                return(BadRequest(validations));
            }

            //Return contract
            return(Ok(ContractUtils.GenerateContract(entity)));
        }
        public async Task <IActionResult> DeleteShooterAssociationInfo(ShooterAssociationInfoRequest request)
        {
            //Recupero l'elemento dal business layer
            var entity = BasicLayer.GetShooterAssociationInfo(request.ShooterAssociationInfoId);

            //Se l'utente non hai i permessi non posso rimuovere entità con userId nullo
            if (entity == null)
            {
                return(NotFound());
            }
            //Invocazione del service layer
            var validations = await BasicLayer.DeleteShooterAssociationInfo(entity, PlatformUtils.GetIdentityUserId(User));

            if (validations.Count > 0)
            {
                return(BadRequest(validations));
            }

            //Return contract
            return(Ok(new OkResponse {
                Status = true
            }));
        }
        public async Task <IActionResult> UpdateAssociation([EntityId] AssociationUpdateRequest request)
        {
            //Recupero l'elemento dal business layer
            var entity = BasicLayer.GetAssociation(request.AssociationId);

            //modifica solo se admin o se utente richiedente è lo stesso che ha creato
            if (entity == null)
            {
                return(NotFound());
            }

            //Aggiornamento dell'entità
            entity.Name            = request.Name;
            entity.Classifications = request.Classifications;
            entity.Categories      = request.Categories;
            entity.Divisions       = request.Divisions;

            entity.FirstPenaltyLabel         = request.FirstPenaltyLabel;
            entity.HitOnNonThreatPointDown   = request.HitOnNonThreatPointDown;
            entity.FirstProceduralPointDown  = request.FirstProceduralPointDown;
            entity.SecondPenaltyLabel        = request.SecondPenaltyLabel;
            entity.SecondProceduralPointDown = request.SecondProceduralPointDown;
            entity.ThirdPenaltyLabel         = request.ThirdPenaltyLabel;
            entity.ThirdProceduralPointDown  = request.ThirdProceduralPointDown;
            entity.SoRoles = request.SoRoles;

            //Salvataggio
            var validations = await BasicLayer.UpdateAssociation(entity, PlatformUtils.GetIdentityUserId(User));

            if (validations.Count > 0)
            {
                return(BadRequest(validations));
            }

            //Confermo
            return(Ok(ContractUtils.GenerateContract(entity)));
        }
Example #26
0
        public IActionResult UpdateProfile(UserUpdateRequest request)
        {
            //User id corrente
            var userId = PlatformUtils.GetIdentityUserId(User);

            //modifica solo se admin o se sè stesso o è autorizzato
            if (request.UserId != userId)
            {
                return(Unauthorized());
            }

            //Recupero l'elemento dal business layer
            var entity = AuthorizationLayer.GetUserById(request.UserId);

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

            //Aggiornamento dell'entità
            entity.Username  = request.Username;
            entity.FirstName = request.FirstName;
            entity.LastName  = request.LastName;
            entity.Email     = request.Email;
            entity.BirthDate = request.BirthDate;

            //Salvataggio
            var validations = AuthorizationLayer.UpdateUser(entity);

            if (validations.Count > 0)
            {
                return(BadRequest(validations));
            }

            //Confermo
            return(Ok(ContractUtils.GenerateContract(entity)));
        }
        public async Task <IActionResult> UpdateMatch([EntityId] MatchUpdateRequest request)
        {
            //Recupero l'elemento dal business layer
            var entity = BasicLayer.GetMatch(request.MatchId);

            //modifica solo se admin o se utente richiedente è lo stesso che ha creato
            if (entity == null)
            {
                return(NotFound());
            }

            //Aggiornamento dell'entità
            entity.Name = request.Name;
            entity.MatchDateTimeStart   = request.MatchDateTimeStart;
            entity.MatchDateTimeEnd     = request.MatchDateTimeEnd;
            entity.AssociationId        = request.AssociationId;
            entity.PlaceId              = request.PlaceId;
            entity.OpenMatch            = request.OpenMatch;
            entity.UnifyClassifications = request.UnifyClassifications;
            entity.Cost           = request.Cost;
            entity.PaymentDetails = request.PaymentDetails;

            //Salvataggio
            var validations = await BasicLayer.UpdateMatch(entity, PlatformUtils.GetIdentityUserId(User));

            if (validations.Count > 0)
            {
                return(BadRequest(validations));
            }

            var association = BasicLayer.GetAssociation(entity.AssociationId);
            var place       = BasicLayer.GetPlace(entity.PlaceId);

            //Confermo
            return(Ok(ContractUtils.GenerateContract(entity, association, place)));
        }
Example #28
0
        public async Task <IActionResult> CreatePermissionOnRole(RolePermissionCreateRequest request)
        {
            //Recupero l'elemento dal business layer
            var permission = AuthorizationLayer.GetPermission(request.PermissionId);

            if (permission == null)
            {
                return(NotFound($"Permission with {request.PermissionId} not found"));
            }

            //Recupero l'elemento dal business layer
            var role = AuthorizationLayer.GetRole(request.RoleId);

            if (role == null)
            {
                return(NotFound($"Role with {request.RoleId} not found"));
            }

            var entity = new PermissionRole()
            {
                PermissionId = permission.Id,
                RoleId       = role.Id
            };
            //Invocazione del service layer
            var validations = await AuthorizationLayer.CreatePermissionRole(entity, PlatformUtils.GetIdentityUserId(User));

            if (validations.Count > 0)
            {
                return(BadRequest(validations));
            }

            var permissions = AuthorizationLayer.FetchPermissionsOnRole(role.Id);

            //Return contract
            return(Ok(permissions.As(ContractUtils.GenerateContract)));
        }
Example #29
0
        public async Task <IActionResult> DeletePermissionOnRole(RolePermissionRequest request)
        {
            //Recupero l'elemento dal business layer
            var entity = AuthorizationLayer.GetPermissionRole(request.PermissionId, request.RoleId);

            //Se l'utente non hai i permessi non posso rimuovere entità con userId nullo
            if (entity == null)
            {
                return(NotFound());
            }

            //Invocazione del service layer
            var validations = await AuthorizationLayer.DeletePermissionRole(entity, PlatformUtils.GetIdentityUserId(User));

            if (validations.Count > 0)
            {
                return(BadRequest(validations));
            }

            var permissions = AuthorizationLayer.FetchPermissionsOnRole(entity.RoleId);

            //Return contract
            return(Ok(permissions.As(ContractUtils.GenerateContract)));
        }
Example #30
0
 public async Task <IActionResult> FetchAllPermissionsOnUser() =>
 Ok(ContractUtils.GenerateContract(await AuthorizationLayer.GetUserPermissionById(PlatformUtils.GetIdentityUserId(User))));