예제 #1
0
        public async Task <IHttpCallResultCGHT <xDTO.Resource> > UpdateResourceAsync(xDTO.Resource item)
        {
            var retVal = await SerializationHelper.Instance.SerializeCallResultsPut <xDTO.Resource>(
                Log, GetClient(),
                $"{ExecutionContext.BaseWebApiUrl}Resources/{item.Id}", item);

            return(retVal);
        }
        public async Task <IHttpActionResult> Put(System.Guid id, [FromBody] dtoRS.Resource dtoItem)
        {
            try
            {
                if (!base.OnActionExecuting(out HttpStatusCode httpStatusCode, out string message))
                {
                    return(Content(httpStatusCode, message));
                }

                if (dtoItem == null)
                {
                    return(BadRequest());
                }

                dtoItem.Id = id;

                var updatedDBItem = _factory.Create(dtoItem);                 // map
                var result        = await Repo.UpdateAsync(updatedDBItem);

                RunCustomLogicAfterUpdatePut(ref updatedDBItem, ref result);

                if (result.Status == cghEnums.RepositoryActionStatus.Updated)
                {
                    // map to dto
                    var updatedDTOItem = _factory.Create(result.Entity);
                    return(Ok(updatedDTOItem));
                }
                else if (result.Status == cghEnums.RepositoryActionStatus.NotFound)
                {
                    return(NotFound());
                }

                Warn("Unable to update object via Web API", LogMessageType.Instance.Warn_WebApi, result.Exception, httpResponseStatusCode: 400, url: Request.RequestUri.ToString());
                return(BadRequest());
            }
            catch (Exception ex)
            {
                Error(message: ex.Message, logMessageType: LogMessageType.Instance.Exception_WebApi, ex: ex);

                if (System.Diagnostics.Debugger.IsAttached)
                {
                    System.Diagnostics.Debugger.Break();
                }

                return(InternalServerError());
            }
        }
예제 #3
0
 public static dataRS.Resource ToModelData(this dtoRS.Resource source)
 {
     return(new dataRS.Resource()
     {
         CreatedBy = source.CreatedBy,
         CreatedDate = source.CreatedDate,
         Description = source.Description,
         Id = source.Id,
         ImageLink = source.ImageLink,
         ImageLinkThumb = source.ImageLinkThumb,
         IsActive = source.IsActive,
         IsDeleted = source.IsDeleted,
         Name = source.Name,
         UpdatedBy = source.UpdatedBy,
         UpdatedDate = source.UpdatedDate,
     });
 }
        public async Task <IHttpActionResult> Post([FromBody] dtoRS.Resource dtoItem)
        {
            try
            {
                if (!base.OnActionExecuting(out HttpStatusCode httpStatusCode, out string message))
                {
                    return(Content(httpStatusCode, message));
                }

                if (dtoItem == null)
                {
                    return(BadRequest());
                }

                // try mapping & saving
                var newDBItem = _factory.Create(dtoItem);

                var result = await Repo.InsertAsync(newDBItem);

                RunCustomLogicAfterInsert(ref newDBItem, ref result);

                if (result.Status == cghEnums.RepositoryActionStatus.Created)
                {                   // map to dto
                    var newDTOItem   = _factory.Create(result.Entity);
                    var uriFormatted = Request.RequestUri.ToString().EndsWith("/") == true?Request.RequestUri.ToString().Substring(0, Request.RequestUri.ToString().Length - 1) : Request.RequestUri.ToString();

                    return(Created($"{uriFormatted}/{newDTOItem.Id}", newDTOItem));
                }

                Warn("Unable to create object via Web API", LogMessageType.Instance.Warn_WebApi, result.Exception, httpResponseStatusCode: 400, url: Request.RequestUri.ToString());
                return(BadRequest());
            }
            catch (Exception ex)
            {
                Error(message: ex.Message, logMessageType: LogMessageType.Instance.Exception_WebApi, ex: ex);

                if (System.Diagnostics.Debugger.IsAttached)
                {
                    System.Diagnostics.Debugger.Break();
                }

                return(InternalServerError());
            }
        }
예제 #5
0
 public Resource(ILoggingService log, IDataService <IWebApiDataServiceRS> dataService, xDTO.Resource dto) : this(log, dataService)
 {
     _dto = dto;
 }
예제 #6
0
 public Resource(ILoggingService log, IDataService <IWebApiDataServiceRS> dataService) : base(log, dataService)
 {
     _dto = new xDTO.Resource();
     OnLazyLoadRequest += HandleLazyLoadRequest;
 }