public async Task <SystemPhoneNumberModel> Validate(SystemPhoneNumberModel model)
        {
            if (string.IsNullOrEmpty(model.Number))
            {
                throw new PhoneNumberIsRequiredException();
            }

            model.Type = await _systemLookupItemService.GetItem("Phone Number Types", model.Type.Id);

            return(model);
        }
Exemplo n.º 2
0
        public async Task <SystemWebsiteModel> Validate(SystemWebsiteModel model)
        {
            if (string.IsNullOrEmpty(model.Url))
            {
                throw new WebsiteUrlIsRequiredException();
            }

            model.Type = await _systemLookupItemService.GetItem("Website Types", model.Type.Id);

            return(model);
        }
        public async Task <SystemEmailAddressModel> Validate(SystemEmailAddressModel model)
        {
            if (model.Address == string.Empty)
            {
                throw new AddressLine1IsRequiredException();
            }

            model.Type = await _systemLookupItemService.GetItem("Email Address Types", model.Type.Id);

            return(model);
        }
Exemplo n.º 4
0
        public async Task <SystemAddressModel> Validate(SystemAddressModel model)
        {
            if (model.Type.Id == string.Empty)
            {
                throw new AddressTypeIdIsRequiredException();
            }
            model.Type = await _systemLookupItemService.GetItem("Address Types", model.Type.Id);

            if (model.Line1 == string.Empty)
            {
                throw new AddressLine1IsRequiredException();
            }
            if (model.City == string.Empty)
            {
                throw new AddressCityIsRequiredException();
            }

            if (model.State.Id == string.Empty)
            {
                throw new AddressStateIdIsRequiredException();
            }
            model.State = await _systemLookupItemService.GetItem("States", model.State.Id);

            if (model.PostalCode == string.Empty)
            {
                throw new AddressPostalCodeIsRequiredException();
            }
            var code = model.PostalCode.Split('_');

            if (code.Length - 1 >= 0 && code[0] != null && !int.TryParse(code[0], out int code1))
            {
                throw new AddressPostalCodeIsInvalidException();
            }
            if (code.Length - 1 >= 1 && code[1] != null && !int.TryParse(code[1], out int code2))
            {
                throw new AddressPostalCodeIsInvalidException();
            }

            if (model.Country.Id == string.Empty)
            {
                throw new AddressCountryIdIsRequiredException();
            }
            model.Country = await _systemLookupItemService.GetItem("Countries", model.Country.Id);

            return(model);
        }
Exemplo n.º 5
0
        public async Task <IActionResult> Get(string key)
        {
            var isGuid = Guid.TryParse(key, out var id);

            try
            {
                var model = isGuid ? await _systemLookupItemService.GetItem(id) : await _systemLookupItemService.GetItem(key);

                var responseMessage = isGuid ? string.Format("System LookupItem with ID '{0}' found.", id) : string.Format("System LookupItem group '{0}' found.", key);
                responseModels.Add("Lookup Items", model);
                response = new ApiResponse(HttpStatusCode.OK, responseMessage, null, responseModels);
                return(Ok(new { response }));
            }
            catch (SystemLookupItemNotFoundException exception)
            {
                response = new ApiResponse(HttpStatusCode.Conflict, isGuid ? string.Format("System LookupItem with ID '{0}' not found.", key) : string.Format("System LookupItem group '{0}' not found.", key), null);
                return(Ok(new { response }));
            }
            catch (Exception exception)
            {
                return(BadRequest("Error setting up tenant service desk. Error: " + exception.Message));
            }
        }
        /// <summary>
        /// Creates multiple items in the System Subscriptions container.
        /// </summary>
        /// <param name="model">A SystemResetModel object.</param>
        /// <returns></returns>
        private async Task createContainerSubscriptions(SystemResetModel model)
        {
            if (model.Subscriptions == null)
            {
                return;
            }

            foreach (SubscriptionModel subscriptionModel in model.Subscriptions)
            {
                //  If a renewal timeframe exists, retrieve it. Otherwise, make it null.
                subscriptionModel.RenewalTimeframe = subscriptionModel.RenewalTimeframe == null ? null : await _systemLookupItemService.GetItem("Subscription Renewal Timeframes", subscriptionModel.RenewalTimeframe.Id);

                var entity = new Subscription(subscriptionModel);
                await _systemSubscriptionService.CreateItem(entity);
            }
        }