Пример #1
0
        /// <summary>
        /// Accept/Deny the invitation. Stores accepted invitation to pp.
        /// </summary>
        /// <param name="invitationId"></param>
        /// <param name="accepted"></param>
        /// <param name="userEmail"></param>
        /// <returns></returns>
        public async Task <Invitation> ProcessInvitation(string invitationId, bool accepted, string userEmail)
        {
            var invitation = await GetInvitation(invitationId);

            if (invitation == null)
            {
                throw new Exception("Invitation not found");
            }

            var pp = await placeProviderRepository.GetPlaceProvider(invitation.PlaceProviderId);

            if (pp == null)
            {
                throw new Exception("Invitation place provider has not been found");
            }

            if (invitation.Status != InvitationStatus.Invited)
            {
                throw new Exception("Invitation has been already processed");
            }
            if (invitation.Email != userEmail)
            {
                throw new Exception("Invitation has been sent to someone else");
            }
            invitation.CompanyName = pp.CompanyName;
            invitation.StatusTime  = DateTimeOffset.Now;
            if (accepted)
            {
                invitation.Status = InvitationStatus.Accepted;
            }
            else
            {
                invitation.Status = InvitationStatus.Declined;
            }
            invitation = await SetInvitation(invitation, false);

            if (accepted)
            {
                if (pp.Users == null)
                {
                    pp.Users = new List <Invitation>();
                }
                if (!pp.Users.Any(p => p.Email == userEmail))
                {
                    pp.Users.Add(invitation);
                    await placeProviderRepository.SetPlaceProvider(pp);
                }
            }

            return(invitation);
        }
Пример #2
0
        public async Task <ActionResult <PlaceProvider> > UpdatePP([FromBody] PlaceProvider placeProvider)
        {
            try
            {
                if (placeProvider is null)
                {
                    throw new ArgumentNullException(nameof(placeProvider));
                }

                if (string.IsNullOrEmpty(placeProvider.PlaceProviderId))
                {
                    throw new Exception("Invalid data has been received");
                }
                if (string.IsNullOrEmpty(placeProvider.MainContact))
                {
                    throw new Exception("Place provide your name in the registration form");
                }
                if (string.IsNullOrEmpty(placeProvider.MainEmail) || !placeProvider.MainEmail.IsValidEmail())
                {
                    throw new Exception("Place provide valid main email");
                }
                placeProvider.PrivatePhone = placeProvider.PrivatePhone.FormatPhone();
                if (string.IsNullOrEmpty(placeProvider.PrivatePhone) || !placeProvider.PrivatePhone.IsValidPhoneNumber())
                {
                    throw new Exception("Place provide valid contact phone number in form +421 907 000 000");
                }

                var toUpdate = await placeProviderRepository.GetPlaceProvider(placeProvider.PlaceProviderId);

                if (toUpdate == null)
                {
                    throw new Exception("Place provider has not been found");
                }

                if (!string.IsNullOrEmpty(placeProvider.CompanyId))
                {
                    toUpdate.CompanyId = placeProvider.CompanyId;
                }
                if (!string.IsNullOrEmpty(placeProvider.CompanyName))
                {
                    toUpdate.CompanyName = placeProvider.CompanyName;
                }
                if (!string.IsNullOrEmpty(placeProvider.Country))
                {
                    toUpdate.Country = placeProvider.Country;
                }
                if (!string.IsNullOrEmpty(placeProvider.CSS))
                {
                    toUpdate.CSS = placeProvider.CSS;
                }
                if (!string.IsNullOrEmpty(placeProvider.Logo))
                {
                    toUpdate.Logo = placeProvider.Logo;
                }
                if (!string.IsNullOrEmpty(placeProvider.MainContact))
                {
                    toUpdate.MainContact = placeProvider.MainContact;
                }
                if (!string.IsNullOrEmpty(placeProvider.MainEmail))
                {
                    toUpdate.MainEmail = placeProvider.MainEmail;
                }
                if (!string.IsNullOrEmpty(placeProvider.PrivatePhone))
                {
                    toUpdate.PrivatePhone = placeProvider.PrivatePhone;
                }
                if (!string.IsNullOrEmpty(placeProvider.PublicEmail))
                {
                    toUpdate.PublicEmail = placeProvider.PublicEmail;
                }
                if (!string.IsNullOrEmpty(placeProvider.PublicPhone))
                {
                    toUpdate.PublicPhone = placeProvider.PublicPhone;
                }
                if (!string.IsNullOrEmpty(placeProvider.VAT))
                {
                    toUpdate.VAT = placeProvider.VAT;
                }
                if (!string.IsNullOrEmpty(placeProvider.Web))
                {
                    toUpdate.Web = placeProvider.Web;
                }
                if (!string.IsNullOrEmpty(placeProvider.SupportEmail))
                {
                    toUpdate.SupportEmail = placeProvider.SupportEmail;
                }
                if (!string.IsNullOrEmpty(placeProvider.SupportName))
                {
                    toUpdate.SupportName = placeProvider.SupportName;
                }
                if (!string.IsNullOrEmpty(placeProvider.SupportPhone))
                {
                    toUpdate.SupportPhone = placeProvider.SupportPhone;
                }

                return(Ok(await placeProviderRepository.SetPlaceProvider(toUpdate)));
            }
            catch (ArgumentException exc)
            {
                logger.LogError(exc.Message);
                return(BadRequest(new ProblemDetails()
                {
                    Detail = exc.Message
                }));
            }
            catch (Exception exc)
            {
                logger.LogError(exc, exc.Message);
                return(BadRequest(new ProblemDetails()
                {
                    Detail = exc.Message
                }));
            }
        }