示例#1
0
        /// <summary>
        /// Adiciona un caso en la aplicación Service Desk
        /// </summary>
        /// <param name="input">Parámetros para crear un caso </param>
        /// <param name="user">Usuario autenticado</param>
        /// <returns>estado del caso creado</returns>
        public async Task <OutputResponseCaseAsdkV8Dto> Create(InputCreateCaseAsdkV8Dto input)
        {
            UrlParameters parameterUrl = new UrlParameters
            {
                itemType = input.CaseType
            };

            string uriCreateCase = ConfigurationService.UrlCreateCase.ConvertUrl(parameterUrl);
            string endpoint      = ConfigurationService.UrlServiceDesk + uriCreateCase;

            CreateCaseV8 createCase = input.MapperModel(new CreateCaseV8());

            createCase.AuthorId = Principal.User().Id;

            List <AnswerGeneralV8Api> listProperty = new List <AnswerGeneralV8Api>();

            listProperty.FillProperties(createCase, true);

            List <AnswerGeneralV8Api> answerApi = await ConnectionService.PostAsync <List <AnswerGeneralV8Api> >(Principal.User().KeyAuthorization, endpoint, listProperty);

            OutputResponseCaseAsdkV8Dto answerCreate = answerApi.ConvertModel(new OutputResponseCaseAsdkV8Dto());

            if (input.AdditionalFields?.Count > 0 && answerCreate?.ItemId > 0)
            {
                await UpdateAdditionalFields(input.AdditionalFields, answerCreate.ItemId, input.CaseType);
            }

            return(answerCreate);
        }
示例#2
0
        /// <summary>
        /// Establece la configuración para autenticar al usuario
        /// </summary>
        /// <param name="model">parámetros de autenticación</param>
        /// <param name="urlServiceDesk">endpoint de Service Desk</param>
        /// <returns>token</returns>
        public async Task <AnswerAuthentication> AuthenticateV8(InputAuthenticateDto model)
        {
            List <AnswerGeneralV8Api> listProperty = new List <AnswerGeneralV8Api>();

            listProperty.FillProperties(model, true);

            string endpoint = ConfigurationService.UrlServiceDesk + ConfigurationService.UrlLogin;

            List <AnswerGeneralV8Api> answerApi = await ConectionService.PostAsync <List <AnswerGeneralV8Api> >(string.Empty, endpoint, listProperty);

            return(answerApi.ConvertModel(new AnswerAuthentication()));
        }
示例#3
0
        public async Task <OutputParametersDto> GetProject()
        {
            string uri      = ConfigurationService.UrlProjects;
            string endpoint = ConfigurationService.UrlServiceDesk + uri;

            dynamic obj = new
            {
                consoleType = Constants.TypeConsole_Specialist
            };

            AnswerGetProjectV9Api projectAsdkV9 = await ConnectionService.PostAsync <AnswerGetProjectV9Api>(token, endpoint, obj, Constants.NameHeaderTokenASDK_V9);

            return(new OutputParametersDto
            {
                Parameters = projectAsdkV9.Content.MapperModelParameters()
            });
        }
        public async Task <List <AdditionalFieldsV9> > GetAdditionalField(int itemType, int stateId, int categoryId)
        {
            var token = Principal.TokenAuthenticationASDK_V9();

            ModelByCategoryV9 modelByCategory = await ManagmentParametersV9Service.GetModelByCategory(itemType, categoryId);

            InputGetAdditionalFieldsAsdkV9Dto inputGetAdditionalFields = new InputGetAdditionalFieldsAsdkV9Dto
            {
                categoryId  = categoryId,
                consoleType = Constants.TypeConsole_Specialist,
                itemType    = itemType,
                modelId     = modelByCategory.Id,
                stateId     = stateId
            };

            string uriAdditionalFields = ConfigurationService.UrlAdditionalFieldsAsdkV9;
            string endpoint            = ConfigurationService.UrlServiceDesk + uriAdditionalFields;

            AnswerAdditionalFieldsAsdkV9Api AdditionalFieldsAsdkV9 = await ConnectionService.PostAsync <AnswerAdditionalFieldsAsdkV9Api>(token, endpoint, inputGetAdditionalFields, Constants.NameHeaderTokenASDK_V9);

            return(AdditionalFieldsAsdkV9.Content);
        }
示例#5
0
        public async Task <OutputResponseCaseAsdkV9Dto> Create(InputCreateCaseAsdkV9Dto input)
        {
            string uriCreateCase = ConfigurationService.UrlCreateCase;
            string endpoint      = ConfigurationService.UrlServiceDesk + uriCreateCase;

            ModelByCategoryV9 modelByCategory = await ManagmentParametersV9Service.GetModelByCategory(input.ItemType, input.CategoryId);

            UserASDKV9 userASDKV9 = await ManagmentUserAsdkV9Service.GetUser();

            CreateCaseV9 createCase = input.MapperModel(new CreateCaseV9());

            createCase.authorId       = userASDKV9.Id;
            createCase.tempItemId     = -2;
            createCase.consoleType    = Constants.TypeConsole_Specialist;
            createCase.modelId        = Convert.ToInt32(modelByCategory.Id);
            createCase.isFeeAvailable = true;

            // TimeZoneInfo.ConvertTimeToUtc(thisTime, TimeZoneInfo.Local)
            createCase.instance = new DateTimeOffset(DateTime.UtcNow).ToUnixTimeMilliseconds();

            List <AdditionalFieldsV9> listAdditionalFieldV9 = await ManagmentAdditionalFieldV9Service.GetAdditionalField(input.ItemType, input.StateId, input.CategoryId);

            List <AdditionalFieldsV9> addFieldsV9 = new List <AdditionalFieldsV9>();

            foreach (var item in input.AdditionalFields)
            {
                MapperAdditionalFieldsV9 additionalFieldsV9  = JsonConvert.DeserializeObject <MapperAdditionalFieldsV9>(item.AdvancedFieldId);
                AdditionalFieldsV9       itemInput           = additionalFieldsV9.MapperModel(new AdditionalFieldsV9());
                AdditionalFieldsV9       itemAdditionalField = listAdditionalFieldV9.FirstOrDefault(x => x.Equals(itemInput));

                if (itemAdditionalField != null && !string.IsNullOrWhiteSpace(item.Value))
                {
                    listAdditionalFieldV9.Remove(itemAdditionalField);
                    AdditionalFiieldType fieldType = (AdditionalFiieldType)itemAdditionalField.fieldType;

                    if (fieldType == AdditionalFiieldType.ShortText || fieldType == AdditionalFiieldType.LongText || fieldType == AdditionalFiieldType.Link)
                    {
                        itemAdditionalField.stringValue = item.Value;
                    }

                    if (fieldType == AdditionalFiieldType.CheckBox)
                    {
                        bool.TryParse(item.Value, out bool result);
                        itemAdditionalField.boolValue = result;
                    }

                    if (fieldType == AdditionalFiieldType.Numeric || fieldType == AdditionalFiieldType.Decimal || fieldType == AdditionalFiieldType.Currency)
                    {
                        float.TryParse(item.Value, out float result);
                        itemAdditionalField.floatValue = result;
                    }

                    if (fieldType == AdditionalFiieldType.Datetime || fieldType == AdditionalFiieldType.Date)
                    {
                        DateTime.TryParse(item.Value, out DateTime dateTime);
                        DateTime time = new DateTime(dateTime.Year, dateTime.Month, dateTime.Day, dateTime.Hour, dateTime.Minute, dateTime.Second, DateTimeKind.Local);
                        itemAdditionalField.dateValue = new DateTimeOffset(time).ToUnixTimeMilliseconds();
                    }

                    if (fieldType == AdditionalFiieldType.Time)
                    {
                        Regex reguex = new Regex(Constants.Regex_ValidationTimeSpan);

                        if (reguex.IsMatch(item.Value))
                        {
                            TimeSpan.TryParse(item.Value, out TimeSpan time);
                            DateTime date = new DateTime(1970, 1, 1, time.Hours, time.Minutes, time.Seconds, DateTimeKind.Local);
                            itemAdditionalField.dateValue = new DateTimeOffset(date).ToUnixTimeMilliseconds();
                        }
                    }

                    if (fieldType == AdditionalFiieldType.CatalogTree)
                    {
                        int.TryParse(item.Value, out int result);
                        itemAdditionalField.catalogId = result;
                    }

                    if (fieldType == AdditionalFiieldType.Recursive)
                    {
                        InputMapperRecursiveFieldDto fieldRecursive = JsonConvert.DeserializeObject <InputMapperRecursiveFieldDto>(item.Value);
                        itemAdditionalField.intValue    = fieldRecursive.Id;
                        itemAdditionalField.stringValue = fieldRecursive.Name;
                    }

                    //if (fieldType.Equals(Constants.List) || fieldType.Equals(Constants.CatalogList))
                    //{
                    //    int.TryParse(item.Value, out int result);
                    //    LookupValues selected = itemAdditionalField.LookupValues.FirstOrDefault(x => x.Id == result);
                    //    if (selected != null)
                    //    {
                    //        itemAdditionalField.Selected = selected;
                    //        itemAdditionalField.IntValue = selected.Id;
                    //        itemAdditionalField.StringValue = selected.Name;
                    //    }
                    //}
                }

                addFieldsV9.Add(itemAdditionalField);
            }

            listAdditionalFieldV9.ForEach(item => addFieldsV9.Add(item));

            createCase.listAdditionalField = addFieldsV9;
            AnswerCreateCaseApi answer = await ConnectionService.PostAsync <AnswerCreateCaseApi>(token, endpoint, createCase, Constants.NameHeaderTokenASDK_V9);

            return(answer.MapperModel(new OutputResponseCaseAsdkV9Dto()));
        }