コード例 #1
0
 public HttpResponseMessage GetLocationByID([FromUri] int LocationId, [FromUri] int CustomerId)
 {
     try
     {
         var customer = _CustomerService.GetCustomers().Where(c => c.CustomerId == CustomerId && c.IsActive == true).FirstOrDefault();
         if (customer == null)
         {
             return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "Customer not found."), Configuration.Formatters.JsonFormatter));
         }
         List <string> LocationImages = new List <string>();
         var           Location       = _LocationService.GetLocation(LocationId);
         if (Location != null)
         {
             Mapper.CreateMap <Friendlier.Entity.Location, Friendlier.Models.LocationResponseModel>();
             LocationResponseModel LocationResponseModel = Mapper.Map <Friendlier.Entity.Location, Friendlier.Models.LocationResponseModel>(Location);
             //LocationResponseModel.ContactInfo = Location.MobileNo + "|" + Location.EmailId;
             var images = _LocationImagesService.GetLocationImages().Where(l => l.LocationId == LocationId).ToList();
             if (images.Count() > 0)
             {
                 foreach (var image in images)
                 {
                     LocationImages.Add(image.ImagePath);
                 }
             }
             // LocationResponseModel.ContactInfo = Location.MobileNo + "|" + Location.EmailId;
             LocationResponseModel.LocationImages = LocationImages;
             var tags = _LocationTagService.GetLocationTags().Where(t => t.LocationId == LocationId).Select(t => t.Tag).ToList();
             if (tags.Count() > 0)
             {
                 string tagList = "";
                 foreach (var tag in tags)
                 {
                     tagList = tagList + "," + tag;
                 }
                 LocationResponseModel.Tags = tagList.TrimEnd(',').TrimStart(',');
             }
             var isFavourite = _FavoriteService.GetFavorites().Where(f => f.LocationId == LocationId && f.CustomerId == CustomerId).FirstOrDefault();
             if (isFavourite == null)
             {
                 LocationResponseModel.IsFavourite = false;
             }
             else
             {
                 LocationResponseModel.IsFavourite = true;
             }
             return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("success", LocationResponseModel), Configuration.Formatters.JsonFormatter));
         }
         else
         {
             return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "Location not found."), Configuration.Formatters.JsonFormatter));
         }
     }
     catch (Exception ex)
     {
         string ErrorMsg = ex.Message.ToString();
         ErrorLogging.LogError(ex);
         return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "User not found."), Configuration.Formatters.JsonFormatter));
     }
 }
コード例 #2
0
        public static LocationResponseModel GetLocationList()
        {
            LocationResponseModel location = new LocationResponseModel();

            location.LocationList = new List <LocationModel>()
            {
                new LocationModel()
                {
                    Name = "australiaeast", DisplayName = "Australia East",
                },
                new LocationModel()
                {
                    Name = "australiasoutheast", DisplayName = "Australia Southeast",
                },
                new LocationModel()
                {
                    Name = "centralindia", DisplayName = "Central India",
                },
                new LocationModel()
                {
                    Name = "centralus", DisplayName = "Central US",
                },
                new LocationModel()
                {
                    Name = "eastasia", DisplayName = "East Asia",
                },
                new LocationModel()
                {
                    Name = "eastus", DisplayName = "East US",
                },
                new LocationModel()
                {
                    Name = "eastus2", DisplayName = "East US 2",
                },
                new LocationModel()
                {
                    Name = "japaneast", DisplayName = "Japan East",
                },
                new LocationModel()
                {
                    Name = "japanwest", DisplayName = "Japan West",
                },
                new LocationModel()
                {
                    Name = "northeurope", DisplayName = "North Europe",
                },
                new LocationModel()
                {
                    Name = "southindia", DisplayName = "South India",
                },
                new LocationModel()
                {
                    Name = "southeastasia", DisplayName = "Southeast Asia",
                },
                new LocationModel()
                {
                    Name = "uksouth", DisplayName = "UK South",
                },
                new LocationModel()
                {
                    Name = "ukwest", DisplayName = "UK West",
                },
                new LocationModel()
                {
                    Name = "westcentralus", DisplayName = "West Central US",
                },
                new LocationModel()
                {
                    Name = "westeurope", DisplayName = "West Europe",
                },
                new LocationModel()
                {
                    Name = "westus", DisplayName = "West US",
                },
                new LocationModel()
                {
                    Name = "westus2", DisplayName = "West US 2",
                },
            };

            return(location);
        }
コード例 #3
0
        public HttpResponseMessage SaveLocation([FromBody] LocationModel LocationModel)
        {
            int locationId = 0;

            try
            {
                if (LocationModel.CustomerId == 0)
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "Customer Id is blank"), Configuration.Formatters.JsonFormatter));
                }
                if (LocationModel.Title == null || LocationModel.Title == "")
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "Title is blank"), Configuration.Formatters.JsonFormatter));
                }
                if (LocationModel.Description == null || LocationModel.Description == "")
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "Description is blank"), Configuration.Formatters.JsonFormatter));
                }
                //if (LocationModel.ContactInfo == null && LocationModel.ContactInfo == "")
                //{
                //    return Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "ContactInfo is blank"), Configuration.Formatters.JsonFormatter);
                //}
                if (LocationModel.Street == null || LocationModel.Street == "")
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "Street is blank"), Configuration.Formatters.JsonFormatter));
                }
                if (LocationModel.City == null || LocationModel.City == "")
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "City is blank"), Configuration.Formatters.JsonFormatter));
                }
                if (LocationModel.State == null || LocationModel.State == "")
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "State is blank"), Configuration.Formatters.JsonFormatter));
                }
                if (LocationModel.Country == null || LocationModel.Country == "")
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "Country is blank"), Configuration.Formatters.JsonFormatter));
                }
                if (LocationModel.CategoryIds == null || LocationModel.CategoryIds == "")
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "CategoryIds is blank"), Configuration.Formatters.JsonFormatter));
                }
                if (LocationModel.Ratings == 0)
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "Ratings is blank"), Configuration.Formatters.JsonFormatter));
                }

                var customer = _CustomerService.GetCustomers().Where(c => c.CustomerId == LocationModel.CustomerId && c.IsActive == true).FirstOrDefault();
                if (customer != null)
                {
                    var street = _LocationService.GetLocations().Where(l => l.Street.ToLower() == LocationModel.Street.ToLower()).Distinct().ToList();
                    if (street.Count() > 0)
                    {
                        var entity1 = street.Where(l => l.City.ToLower() == LocationModel.City.ToLower()).Distinct().ToList();
                        if (entity1.Count() > 0)
                        {
                            var entity2 = street.Where(l => l.State.ToLower() == LocationModel.State.ToLower()).Distinct().ToList();
                            if (entity2.Count() > 0)
                            {
                                var entity3 = street.Where(l => l.Country.ToLower() == LocationModel.Country.ToLower()).Distinct().ToList();
                                if (entity3.Count() > 0)
                                {
                                    return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "this location already exists."), Configuration.Formatters.JsonFormatter));
                                }
                            }
                        }
                    }


                    string[] categoryIds = LocationModel.CategoryIds.Split(',');

                    List <int> CatIds = _CategoryService.GetCategories().Select(c => c.CategoryId).ToList();
                    // var CatIds = Categories.Select(c => c.CategoryId);
                    List <string> Ids       = CatIds.ConvertAll <string>(x => x.ToString());
                    bool          isMatched = true;
                    foreach (var item in categoryIds)
                    {
                        if (!Ids.Contains(item))
                        {
                            isMatched = false;
                        }
                    }
                    IEnumerable <string> difference = Ids.Except(categoryIds);
                    if (isMatched)
                    {
                        Mapper.CreateMap <Friendlier.Models.LocationModel, Friendlier.Entity.Location>();
                        Friendlier.Entity.Location location = Mapper.Map <Friendlier.Models.LocationModel, Friendlier.Entity.Location>(LocationModel);
                        //string[] contactDetails = LocationModel.ContactInfo.Split('|');
                        //location.EmailId = contactDetails[1];
                        //location.MobileNo = contactDetails[0];
                        location.EmailId     = LocationModel.EmailId;
                        location.MobileNo    = LocationModel.MobileNo;
                        location.CategoryIds = LocationModel.CategoryIds;
                        location.IsApproved  = false;
                        location.Status      = EnumValue.GetEnumDescription(EnumValue.LocationStatus.New);
                        _LocationService.InsertLocation(location);
                        locationId = location.LocationId;
                        if (LocationModel.Tags != null && LocationModel.Tags != "")
                        {
                            string[] tagList = LocationModel.Tags.Split(',');
                            foreach (var tag in tagList)
                            {
                                LocationTag locationTag = new LocationTag();
                                locationTag.LocationId = locationId;
                                locationTag.Tag        = tag;
                                _LocationTagService.InsertLocationTag(locationTag);
                            }
                        }


                        Mapper.CreateMap <Location, LocationResponseModel>();
                        LocationResponseModel model = Mapper.Map <Location, LocationResponseModel>(location);
                        model.Tags = LocationModel.Tags;
                        SendMailToAdmin(customer.FirstName, model.Title, model.Street + " " + model.City + " " + model.State + " " + model.Country);
                        //model.ContactInfo = location.MobileNo + "|" + location.EmailId;
                        return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("success", model), Configuration.Formatters.JsonFormatter));
                    }

                    else
                    {
                        return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "Category id is wrong."), Configuration.Formatters.JsonFormatter));
                    }
                }

                else
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "Customer id is wrong."), Configuration.Formatters.JsonFormatter));
                }
            }
            catch (Exception ex)
            {
                string ErrorMsg = ex.Message.ToString();
                ErrorLogging.LogError(ex);
                return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "Please try again."), Configuration.Formatters.JsonFormatter));
            }
        }
コード例 #4
0
        public HttpResponseMessage SearchLocation([FromUri] string searchTerm)
        {
            var models = new List <LocationResponseModel>();

            try
            {
                if (searchTerm == null || searchTerm == "")
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "searchTerm is blank"), Configuration.Formatters.JsonFormatter));
                }
                string[]   searchList     = searchTerm.ToLower().Split(' ');
                List <int> locationIdList = _LocationTagService.GetLocationTags().Where(x => x.Tag.ToLower().Contains(searchTerm.ToLower())).Select(x => x.LocationId).Distinct().ToList();

                //  var locationsList = _LocationService.GetLocations().Where(l => l.Title.ToLower().Contains(searchTerm.ToLower()) || l.Address.ToLower().Contains(searchTerm.ToLower()) || locationIdList.Contains(l.LocationId) && l.IsApproved==true).ToList();
                var locationsList = _LocationService.GetLocations().Where(l => l.Title.ToLower().Contains(searchTerm.ToLower()) || searchList.Contains(l.City.ToLower()) || searchList.Contains(l.Street.ToLower()) || searchList.Contains(l.Country.ToLower()) || searchList.Contains(l.State.ToLower()) || locationIdList.Contains(l.LocationId) && l.IsApproved == true).ToList();
                var entity1       = locationsList;
                var entity2       = _CustomerService.GetCustomers().Where(c => c.IsActive == true);

                var locations = (from x in entity1
                                 join y in entity2
                                 on x.CustomerId equals y.CustomerId
                                 select x).ToList();


                if (locations.Count > 0)
                {
                    Mapper.CreateMap <Location, LocationResponseModel>();
                    //var tags = _LocationTagService.GetLocationTags();
                    //if (tags != null)
                    //{
                    //    tags = tags.Where(t => t.Tag.ToLower().Contains(searchTerm.ToLower())).ToList();

                    //    foreach (var tag in tags)
                    //    {
                    //        var locationList = _LocationService.GetLocations().Where(l => l.LocationId == tag.LocationId).FirstOrDefault();
                    //        LocationResponseModel loc = Mapper.Map<Location, LocationResponseModel>(locationList);
                    //        models.Add(loc);
                    //    }

                    //}
                    //locations = locations.Where(l => l.Title.ToLower().Contains(searchTerm.ToLower())).ToList();
                    foreach (var location in locations)
                    {
                        LocationResponseModel loc = Mapper.Map <Location, LocationResponseModel>(location);
                        var tags = _LocationTagService.GetLocationTags().Where(t => t.LocationId == loc.LocationId).Select(t => t.Tag).ToList();
                        if (tags.Count() > 0)
                        {
                            string tagList = "";
                            foreach (var tag in tags)
                            {
                                tagList = tagList + "," + tag;
                            }
                            loc.Tags = tagList.TrimEnd(',').TrimStart(',');
                        }
                        models.Add(loc);
                    }

                    return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("success", models), Configuration.Formatters.JsonFormatter));
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "No location found."), Configuration.Formatters.JsonFormatter));
                }
            }
            catch (Exception ex)
            {
                string ErrorMsg = ex.Message.ToString();
                ErrorLogging.LogError(ex);
                return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "Please try again."), Configuration.Formatters.JsonFormatter));
            }
        }
コード例 #5
0
        public HttpResponseMessage UpdateLocation([FromBody] LocationModel LocationModel)
        {
            try
            {
                if (LocationModel.CustomerId == 0)
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "Customer Id is blank"), Configuration.Formatters.JsonFormatter));
                }
                var customer = _CustomerService.GetCustomers().Where(c => c.CustomerId == LocationModel.CustomerId && c.IsActive == true).FirstOrDefault();
                if (customer == null)
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "Customer not found."), Configuration.Formatters.JsonFormatter));
                }
                if (LocationModel.LocationId == 0)
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "Location Id is blank"), Configuration.Formatters.JsonFormatter));
                }
                var location = _LocationService.GetLocations().Where(l => l.LocationId == LocationModel.LocationId && l.CustomerId == LocationModel.CustomerId).FirstOrDefault();
                if (location == null)
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "Location not found."), Configuration.Formatters.JsonFormatter));
                }
                else
                {
                    location.Title       = ((LocationModel.Title != null && LocationModel.Title != "") ? LocationModel.Title : location.Title);
                    location.Description = ((LocationModel.Description != null && LocationModel.Description != "") ? LocationModel.Description : location.Description);
                    //if (LocationModel.ContactInfo != null && LocationModel.ContactInfo != "")
                    //{
                    //    string[] contactDetails = LocationModel.ContactInfo.Split('|');
                    //    location.EmailId = contactDetails[1];
                    //    location.MobileNo = contactDetails[0];
                    //}
                    location.EmailId  = ((LocationModel.EmailId != null && LocationModel.EmailId != "") ? LocationModel.EmailId : location.EmailId);
                    location.MobileNo = ((LocationModel.MobileNo != null && LocationModel.MobileNo != "") ? LocationModel.MobileNo : location.MobileNo);
                    location.State    = ((LocationModel.State != null && LocationModel.State != "") ? LocationModel.State : location.State);
                    location.City     = ((LocationModel.City != null && LocationModel.City != "") ? LocationModel.City : location.City);
                    location.Country  = ((LocationModel.Country != null && LocationModel.Country != "") ? LocationModel.Country : location.Country);
                    location.Street   = ((LocationModel.Street != null && LocationModel.Street != "") ? LocationModel.Street : location.Street);
                    location.Ratings  = (LocationModel.Ratings != null ? LocationModel.Ratings : location.Ratings);
                    if (LocationModel.CategoryIds != null && LocationModel.CategoryIds != "")
                    {
                        string[] categoryIds = LocationModel.CategoryIds.Split(',');

                        List <int> CatIds = _CategoryService.GetCategories().Select(c => c.CategoryId).ToList();
                        // var CatIds = Categories.Select(c => c.CategoryId);
                        List <string> Ids       = CatIds.ConvertAll <string>(x => x.ToString());
                        bool          isMatched = true;
                        foreach (var item in categoryIds)
                        {
                            if (!Ids.Contains(item))
                            {
                                isMatched = false;
                            }
                        }
                        IEnumerable <string> difference = Ids.Except(categoryIds);
                        if (isMatched)
                        {
                            location.CategoryIds = LocationModel.CategoryIds;
                        }
                        else
                        {
                            return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "Category id is wrong."), Configuration.Formatters.JsonFormatter));
                        }
                    }
                    //location.CategoryIds = ((LocationModel.CategoryIds != null && LocationModel.CategoryIds != "") ? LocationModel.CategoryIds : location.CategoryIds);

                    _LocationService.UpdateLocation(location);
                    string tags        = "";
                    var    LocationTag = _LocationTagService.GetLocationTags().Where(t => t.LocationId == location.LocationId).ToList();
                    if (LocationModel.Tags != null || LocationModel.Tags != "")
                    {
                        string[] tagList = LocationModel.Tags.Split(',');


                        if (LocationTag.Count() > 0)
                        {
                            foreach (var tag in LocationTag)
                            {
                                _LocationTagService.DeleteLocationTag(tag);
                            }
                        }
                        foreach (var tag in tagList)
                        {
                            LocationTag locationTag = new LocationTag();
                            locationTag.LocationId = location.LocationId;
                            locationTag.Tag        = tag;
                            _LocationTagService.InsertLocationTag(locationTag);
                            tags = tags + "," + tag;
                        }
                    }

                    Mapper.CreateMap <Location, LocationResponseModel>();
                    LocationResponseModel model = Mapper.Map <Location, LocationResponseModel>(location);
                    string[] categoryId         = model.CategoryIds.Split(',');
                    string   categoryNames      = "";
                    foreach (var item in categoryId)
                    {
                        var categoryName = _CategoryService.GetCategories().Where(c => c.CategoryId == Convert.ToInt32(item)).Select(c => c.Name).FirstOrDefault();
                        categoryNames = categoryNames + ',' + categoryName;
                    }
                    model.CategoryNames = categoryNames.TrimStart(',').TrimEnd(',');
                    List <string> LocationImages = new List <string>();
                    var           images         = _LocationImagesService.GetLocationImages().Where(l => l.LocationId == location.LocationId).ToList();
                    if (images.Count() > 0)
                    {
                        foreach (var image in images)
                        {
                            LocationImages.Add(image.ImagePath);
                        }
                    }
                    model.LocationImages = LocationImages;

                    model.Tags = tags.TrimStart(',').TrimEnd(',');
                    // model.ContactInfo = location.MobileNo + "|" + location.EmailId;
                    return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("success", model), Configuration.Formatters.JsonFormatter));
                }
            }
            catch (Exception ex)
            {
                string ErrorMsg = ex.Message.ToString();
                ErrorLogging.LogError(ex);
                return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "Please try again."), Configuration.Formatters.JsonFormatter));
            }
        }