Example #1
0
        //RejectAdoProject

        public async Task <List <ProjectAdo> > RejectAdoProject(List <int> toReject, string rejectReason)
        {
            try
            {
                await base.AddAuthHeaderAsync();

                var data = new RejectededListDto {
                    ToReject = toReject, Reason = rejectReason
                };

                var url         = $"{ApiPart}RejectAdoProject";
                var httpcontent = new StringContent(JsonSerializer.Serialize(data, _options), Encoding.UTF8, "application/json");
                var apiData     = await HttpClientBase.PostAsync(url, httpcontent).ConfigureAwait(false);

                if (apiData.IsSuccessStatusCode)
                {
                    var content = await apiData.Content.ReadAsStringAsync();

                    var ser = JsonSerializer.Deserialize <List <ProjectAdo> >(content, _options);
                    return(ser);
                    //var result = Mapper.Map<List<ProjectAdo>>(ser);
                    //return result;
                }
                else
                {
                    throw new Exception(base.GetErrorText(apiData));
                }
            }
            catch (Exception ex)
            {
                base.HandleException(ex);
                throw;
            }
        }
Example #2
0
        public async Task <List <ProjectAdo> > ApproveAdoProject(List <int> toApprove)
        {
            try
            {
                await base.AddAuthHeaderAsync();

                var url         = $"{ApiPart}ApproveAdoProject";
                var httpcontent = new StringContent(JsonSerializer.Serialize(toApprove, _options), Encoding.UTF8, "application/json");
                var apiData     = await HttpClientBase.PostAsync(url, httpcontent).ConfigureAwait(false);

                if (apiData.IsSuccessStatusCode)
                {
                    var content = await apiData.Content.ReadAsStringAsync();

                    var ser = JsonSerializer.Deserialize <List <ProjectAdo> >(content, _options);
                    return(ser);
                }
                else
                {
                    throw new Exception(base.GetErrorText(apiData));
                }
            }
            catch (Exception ex)
            {
                base.HandleException(ex);
                throw;
            }
        }
Example #3
0
        public async Task <TModel> RestAdd <TModel, TDto>(TModel model, string route = null, CancellationToken cancelToken = default) where TModel : class
        {
            if (model == null)
            {
                throw new ArgumentException($"'{nameof(model)}' cannot be null", nameof(model));
            }

            try
            {
                await AddAuthHeaderAsync();

                var url         = string.IsNullOrWhiteSpace(route) ? $"{ApiPart}" : $"{ApiPart}{route}";
                var updateDto   = Mapper.Map <TDto>(model);
                var httpcontent = new StringContent(JsonSerializer.Serialize(updateDto, _options), Encoding.UTF8, "application/json");
                var apiData     = await HttpClientBase.PostAsync(url, httpcontent, cancelToken).ConfigureAwait(false);

                if (apiData.IsSuccessStatusCode)
                {
                    var stream = await apiData.Content.ReadAsStreamAsync();

                    if (stream.Length == 0)
                    {
                        return(null);
                    }
                    var ser = await JsonSerializer.DeserializeAsync <TDto>(stream, _options, cancelToken);

                    if (ser == null)
                    {
                        return(null);
                    }

                    var result = Mapper.Map <TModel>(ser);
                    var con    = await ConvertModelToLocalTimeBase(result);

                    return(con);
                }
                else
                {
                    throw new Exception(GetErrorText(apiData));
                }
            }
            catch (Exception ex)
            {
                HandleException(ex, cancelToken);
                return(null);
            }
        }
Example #4
0
        public async Task <ProjectAdo> AddItemAsync(ProjectAdo item)
        {
            try
            {
                await base.AddAuthHeaderAsync();

                string url = null;
                if (item.Status == Common.AdoServices.Models.Status.Draft)
                {
                    url = $"{ApiPart}SaveDraftAdoProject";
                }
                else
                {
                    url = $"{ApiPart}RequestAdoProject";
                }
                //var url = $"{ApiPart}";
                var httpcontent = new StringContent(JsonSerializer.Serialize(item, _options), Encoding.UTF8, "application/json");
                var apiData     = await HttpClientBase.PostAsync(url, httpcontent).ConfigureAwait(false);

                //HttpResponseMessage
                if (apiData.IsSuccessStatusCode)
                {
                    var content = await apiData.Content.ReadAsStringAsync();

                    var ser = JsonSerializer.Deserialize <ProjectAdo>(content, _options);
                    return(ser);
                    //var result = Mapper.Map<ProjectAdo>(ser);
                    //return result;
                }
                else
                {
                    throw new Exception(GetErrorText(apiData));
                }
            }
            catch (Exception ex)
            {
                base.HandleException(ex);
                throw;
            }
        }