コード例 #1
0
        public async Task <HttpResponseMessage> GetLocationMappingByCode(string ZoneCode, string SupplierCode)
        {
            try
            {
                List <ZoneMappingSearchResponse> zoneMappingSearchResponses = new List <ZoneMappingSearchResponse>();
                _database = MongoDBHandler.mDatabase();
                var collection = _database.GetCollection <ZoneMaster>("ZoneMaster");
                FilterDefinition <ZoneMaster> filterForZone;
                filterForZone = Builders <ZoneMaster> .Filter.Empty;
                if (!string.IsNullOrWhiteSpace(ZoneCode))
                {
                    filterForZone = filterForZone & Builders <ZoneMaster> .Filter.Eq(b => b.Zone_Code, ZoneCode);
                }

                var zoneMasters = await collection.Find(filterForZone).ToListAsync();

                if (!string.IsNullOrWhiteSpace(SupplierCode))
                {
                    zoneMasters.ForEach(a => a.Zone_LocationMapping.RemoveAll(d => !(d.Supplier_code == SupplierCode)));
                }

                foreach (ZoneMaster zm in zoneMasters)
                {
                    ZoneMappingSearchResponse zoneMappingSearchResponse = new ZoneMappingSearchResponse();
                    zoneMappingSearchResponse.ZoneCodes = zm.Zone_Code;
                    List <string>        SupplierCodes  = zm.Zone_LocationMapping.Select(x => x.Supplier_code).Distinct().ToList();
                    List <Zone_Supplier> zone_Suppliers = new List <Zone_Supplier>();
                    foreach (string SupCode in SupplierCodes)
                    {
                        Zone_Supplier zone_Sup = new Zone_Supplier();
                        zone_Sup.SupplierCode = SupCode;
                        List <Zone_LocationMapping> zone_LocationMappings    = zm.Zone_LocationMapping.Where(x => x.Supplier_code == SupCode).ToList();
                        List <ZoneSupplierLocation> ZoneSupplierLocationList = zone_LocationMappings.ConvertAll(x => new ZoneSupplierLocation
                        {
                            Name        = x.Name ?? string.Empty,
                            Code        = x.Code ?? string.Empty,
                            Distance    = x.Distance,
                            Type        = x.ZoneType ?? string.Empty,
                            SubType     = x.ZoneSubType ?? string.Empty,
                            Latitude    = x.Latitude,
                            Longitude   = x.Longitude,
                            FullAddress = x.FullAdress
                        });
                        zone_Sup.MappingLocations = ZoneSupplierLocationList;
                        zone_Suppliers.Add(zone_Sup);
                    }
                    zoneMappingSearchResponse.SupplierCodes = zone_Suppliers;
                    zoneMappingSearchResponses.Add(zoneMappingSearchResponse);
                }
                return(zoneMappingSearchResponses.Count > 0 ? Request.CreateResponse(HttpStatusCode.OK, zoneMappingSearchResponses) : Request.CreateResponse(HttpStatusCode.BadRequest, "Data Not Available for request"));
            }
            catch (Exception ex)
            {
                NLogHelper.Nlogger_LogError.LogError(ex, this.GetType().FullName, Request.GetActionDescriptor().ActionName, Request.RequestUri.PathAndQuery);
                HttpResponseMessage response = Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Server Error. Contact Admin. Error Date : " + DateTime.Now.ToString());
                return(response);
            }
        }
コード例 #2
0
        public async Task <HttpResponseMessage> SearchbyZoneMasterCode(ZoneMappingSearchRequest RQ)
        {
            try
            {
                List <ZoneMappingSearchResponse> zoneResult = new List <ZoneMappingSearchResponse>();

                if (RQ.PageSize == 0)
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, "Page Size should be greater than Zero."));
                }
                else if (RQ.PageNo == 0)
                {
                    RQ.PageNo = 1;
                }

                _database = MongoDBHandler.mDatabase();
                var collection = _database.GetCollection <ZoneMaster>("ZoneMaster");
                FilterDefinition <ZoneMaster> filterForZone;
                filterForZone = Builders <ZoneMaster> .Filter.Empty;
                if (RQ.ZoneCodes.Any())
                {
                    filterForZone = filterForZone & Builders <ZoneMaster> .Filter.In(b => b.Zone_Code, RQ.ZoneCodes.Select(x => x.Trim().ToUpper()));

                    var zoneMasters = await collection.Find(filterForZone).Skip((RQ.PageNo - 1) * RQ.PageSize).Limit(RQ.PageSize).ToListAsync();

                    if (RQ.SupplierCodes.Any())
                    {
                        zoneMasters.ForEach(a => a.Zone_LocationMapping.RemoveAll(d => !(RQ.SupplierCodes.Contains(d.Supplier_code))));
                    }
                    foreach (ZoneMaster zm in zoneMasters)
                    {
                        ZoneMappingSearchResponse zoneMappingSearchResponse = new ZoneMappingSearchResponse();
                        zoneMappingSearchResponse.ZoneCodes = zm.Zone_Code;
                        List <string>        SupplierCodes  = zm.Zone_LocationMapping.Select(x => x.Supplier_code).Distinct().ToList();
                        List <Zone_Supplier> zone_Suppliers = new List <Zone_Supplier>();
                        foreach (string SupCode in SupplierCodes)
                        {
                            Zone_Supplier zone_Sup = new Zone_Supplier();
                            zone_Sup.SupplierCode = SupCode;
                            List <Zone_LocationMapping> zone_LocationMappings    = zm.Zone_LocationMapping.Where(x => x.Supplier_code == SupCode).ToList();
                            List <ZoneSupplierLocation> ZoneSupplierLocationList = zone_LocationMappings.ConvertAll(x => new ZoneSupplierLocation
                            {
                                Name        = x.Name ?? string.Empty,
                                Code        = x.Code ?? string.Empty,
                                Distance    = x.Distance,
                                Type        = x.ZoneType ?? string.Empty,
                                SubType     = x.ZoneSubType ?? string.Empty,
                                Latitude    = x.Latitude,
                                Longitude   = x.Longitude,
                                FullAddress = x.FullAdress
                            });
                            zone_Sup.MappingLocations = ZoneSupplierLocationList;
                            zone_Suppliers.Add(zone_Sup);
                        }
                        zoneMappingSearchResponse.SupplierCodes = zone_Suppliers;
                        zoneResult.Add(zoneMappingSearchResponse);
                    }

                    return(zoneResult.Count > 0 ? Request.CreateResponse(HttpStatusCode.OK, zoneResult) : Request.CreateResponse(HttpStatusCode.BadRequest, "Data Not Available for request"));
                }
                else
                {
                    HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.BadRequest, "Zone Code Length must be greater than Zero");
                    return(response);
                }
            }
            catch (Exception ex)
            {
                NLogHelper.Nlogger_LogError.LogError(ex, this.GetType().FullName, Request.GetActionDescriptor().ActionName, Request.RequestUri.PathAndQuery);
                HttpResponseMessage response = Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Server Error. Contact Admin. Error Date : " + DateTime.Now.ToString());
                return(response);
            }
        }