public HttpResponseMessage GetLocationByGuidAndId(Guid guid, int id)
        {
            var result       = Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Client code does not have an active account");
            var clientEntity = _lookupService.GetClientByGuid(guid);

            if (clientEntity == null)
            {
                _log.Error(string.Format("Failed to lookup Client by GUID: {0}", guid));
            }
            else
            {
                var locationEntity = _lookupService.GetLocationByIdAndClientId(new List <string> {
                    clientEntity.Id.ToString()
                }, id);
                var location = new LocationDTO();
                if (locationEntity != null)
                {
                    location       = LocationMapper.ToDataTransferObject(locationEntity);
                    location.Areas = _lookupService.GetAreasByLocationId(location.Id).Select(x => AreaMapper.ToDataTransferObject(x)).ToList();
                }
                result = Request.CreateResponse(HttpStatusCode.OK, location);
            }
            result.Headers.Add("Access-Control-Allow-Origin", "*");
            return(result);
        }
        public ActionResult <string> Get(int folderID, string ImageId)
        {
            Byte[] imageBytes = null;

            //Add the address of the output files folder of image files
            string imageDataAddress = @"C:\E Drive\Precipoint Coding Chellange\Testing\dzc_output_files\";

            nlogger.Information("Request has arrived to GET method ");

            try
            {
                nlogger.Information("start Checking if the file exist ");
                if (System.IO.File.Exists(imageDataAddress + folderID.ToString() + "\\" + ImageId))
                {
                    nlogger.Information("File found : started reading the file");
                    imageBytes = System.IO.File.ReadAllBytes(imageDataAddress + folderID.ToString() + "\\" + ImageId);
                }

                nlogger.Debug("Returning File");
                return(File(imageBytes, "image/jpeg"));
            }

            catch (Exception ex)
            {
                //Save the logs in bin\Debug\netcoreapp2.1\ImageReaderLogs
                nlogger.Error("File not found exception has been raised :catch block ");
                throw new NotFoundCutomizedException("No Image found", $"Please check your folder path and " +
                                                     $"respective folder for  folderID:{folderID} and ImageId:{ImageId}");
            }
        }
        public Location GetByIdFilteredByClientIds(int id, IEnumerable <int> _validClientIds)
        {
            var location = GetQueryable()
                           .FirstOrDefault(x => _validClientIds.Contains(x.ClientId) && x.Id == id);

            if (location == null)
            {
                _log.Error(string.Format("Failed to find Location with id: {0} associated to user with client credentials for ids: [{1}]",
                                         id, _validClientIds.ConvertIntListToCSV()), new ArgumentException());
            }
            return(location);
        }
Exemple #4
0
        public int?Create(T entity)
        {
            int?id = null;

            if (entity != null)
            {
                var entityType = typeof(T).Name;
                _log.Info(string.Format("Creating {0}", entityType));
                Add(entity);
                int unit = _UnitOfWork.SaveChanges();
                if (unit < 1 || entity.Id <= 0)
                {
                    _log.Error(string.Format("Failed to Create {0}", entityType, new InvalidOperationException()));
                }
                else
                {
                    _log.Info(string.Format("Created {0} with ID:{1}", entityType, entity.Id));
                    id = entity.Id;
                }
            }
            return(id);
        }
        public HttpResponseMessage GetClientByGuid(Guid guid)
        {
            var result       = Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Client code does not have an active account");
            var clientEntity = _lookupService.GetClientByGuid(guid);

            if (clientEntity == null)
            {
                _log.Error(string.Format("Failed to lookup Client by GUID: {0}", guid));
            }
            else
            {
                var client    = ClientMapper.ToDataTransferObject(clientEntity);
                var locations = _lookupService.GetLocationsByClientId(clientEntity.Id);
                if (locations != null && locations.Count() > 0)
                {
                    client.Locations = locations.Select(x => LocationMapper.ToDataTransferObject(x)).ToList();
                }
                result = Request.CreateResponse(HttpStatusCode.OK, client);
            }
            result.Headers.Add("Access-Control-Allow-Origin", "*");
            return(result);
        }
        public HttpResponseMessage GetTourByGuidAndId(Guid guid, int id)
        {
            var result       = Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Client code does not have an active account");
            var clientEntity = _lookupService.GetClientByGuid(guid);

            if (clientEntity == null)
            {
                _log.Error(string.Format("Failed to lookup Client by GUID: {0}", guid));
            }
            else
            {
                var tourEntity = _lookupService.GetTourByIdAndClientId(new List <string> {
                    clientEntity.Id.ToString()
                }, id);
                var tour = new TourDTO();
                if (tourEntity != null)
                {
                    tour = TourMapper.ToDataTransferObject(tourEntity);
                }
                result = Request.CreateResponse(HttpStatusCode.OK, tour);
            }
            result.Headers.Add("Access-Control-Allow-Origin", "*");
            return(result);
        }