Esempio n. 1
0
        public async Task <IActionResult> Index(FilterModel filterModel)
        {
            if (IsAuth())
            {
                _apiConnection.AddHeader(new Dictionary <string, string>()
                {
                    { "Authorization", "bearer " + GetToken() }
                });
                var response = await _apiConnection.Post <BaseResponse <List <GetJobResponse> > >(baseUrl + "Job/GetWithFilter", filterModel);

                if (response.IsSuccess)
                {
                    if (response.Result.State == State.Success)
                    {
                        return(View(new BaseResponse <List <GetJobResponse> >()
                        {
                            Result = response.Result.Result
                        }));
                    }
                    else
                    {
                        return(View(new BaseResponse <List <GetJobResponse> >()
                        {
                            Message = response.Result.Message
                        }));
                    }
                }
                else
                {
                    return(View(new BaseResponse <List <GetJobResponse> >()
                    {
                        Message = response.ErrorMessage
                    }));
                }
            }
            else
            {
                return(View(new BaseResponse <List <GetJobResponse> >()
                {
                    Message = "Please login"
                }));
            }
        }
        public async Task <IActionResult> Create([Bind("Id,Title,Description,DT_Creation,DT_DeadLine,DT_Done,Priority")] TodoItem todoItem)
        {
            StringContent content = new StringContent(JsonConvert.SerializeObject(todoItem), Encoding.UTF8, "application/json");
            var           result  = await _api.Post(content);

            var newItem = JsonConvert.DeserializeObject <TodoItem> ((string)result);

            /*if (ModelState.IsValid)
             * {
             *  _context.Add(todoItem);
             *  await _context.SaveChangesAsync();
             *  return RedirectToAction(nameof(Index));
             * }
             * return View(todoItem);*/
            return(RedirectToAction(nameof(Index)));
        }
        /// <summary>
        /// Creates an entity in Exact Online
        /// </summary>
        /// <param name="entity">Entity to create</param>
        /// <returns>True if succeed</returns>
        public Boolean Create(ref T entity)
        {
            var supportedActions = GetSupportedActions(entity);

            if (!supportedActions.CanCreate)
            {
                throw new Exception("Cannot create entity. Entity does not support creation. Please see the Reference Documentation.");
            }

            // Get Json code
            var created     = false;
            var converter   = new EntityConverter();
            var emptyEntity = Activator.CreateInstance <T>();
            var json        = converter.ConvertObjectToJson(emptyEntity, entity, _entityControllerDelegate);

            // Send to API
            var response = _conn.Post(json);

            if (!response.Contains("error"))
            {
                created = true;

                // Set values of API in account entity (to ensure GUID is set)
                response = ApiResponseCleaner.GetJsonObject(response);
                var ec = new EntityConverter();
                entity = ec.ConvertJsonToObject <T>(response);

                // Try to add the entity to the managed entities collections
                if (!AddEntityToManagedEntitiesCollection(entity))
                {
                    throw new Exception("This entity already exists");
                }

                // Check if the endpoint supports a read action. Some endpoints such as PrintQuotation only support create (POST).
                if (supportedActions.CanRead)
                {
                    // Get entity with linked entities (API Response for creating does not return the linked entities)
                    entity = GetEntity(GetIdentifierValue(entity), _expandfield);
                }
            }
            return(created);
        }
        /// <summary>
        /// Creates an entity in Exact Online
        /// </summary>
        /// <param name="entity">Entity to create</param>
        /// <returns>True if succeed</returns>
        public Boolean Create(ref T entity)
        {
            if (!IsCreateable(entity))
            {
                throw new Exception("Cannot create entity. Entity does not support creation. Please see the Reference Documentation.");
            }

            // Get Json code
            var created     = false;
            var converter   = new EntityConverter();
            var emptyEntity = Activator.CreateInstance <T>();
            var json        = converter.ConvertObjectToJson(emptyEntity, entity, _entityControllerDelegate);

            // Send to API
            var response = _conn.Post(json);

            if (!response.Contains("error"))
            {
                created = true;

                // Set values of API in account entity (to ensure GUID is set)
                response = ApiResponseCleaner.GetJsonObject(response);
                var ec = new EntityConverter();
                entity = ec.ConvertJsonToObject <T>(response);

                // Try to add the entity to the managed entities collections
                if (!AddEntityToManagedEntitiesCollection(entity))
                {
                    throw new Exception("This entity already exists");
                }

                /* IGNORE the additional GET request until it is resolved properly by the API team (https://github.com/exactonline/exactonline-api-dotnet-client/issues/9)
                 * // Get entity with linked entities (API Response for creating does not return the linked entities)
                 * entity = GetEntity(GetIdentifierValue(entity), _expandfield);
                 */
            }
            return(created);
        }
 /// <inheritdoc />
 public async Task <HttpResponse <Annotation> > CreateAnnotation(AnnotationPayload annotationPayload,
                                                                 TextFormat textFormat)
 {
     return(await _apiConnection.Post <Annotation>(textFormat, annotationPayload));
 }