Ejemplo n.º 1
0
 public CountryBase AddCountry(CountryAdd newItem)
 {
     if (!CurrentDbContext.CountryDB.Any(a => a.Name.Contains(newItem.Name)))
     {
         var addedItem = CurrentDbContext.CountryDB.Add(Mapper.Map <Country>(newItem));
         addedItem.SeoName = SeoManager.GetSeoLocation(addedItem.Name);
         CurrentDbContext.SaveChanges();
         return((addedItem == null) ? null : Mapper.Map <CountryBase>(addedItem));
     }
     return(null);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Get one ad with details for ListDetail.cshtml
        /// </summary>
        /// <param name="stringId"></param>
        /// <returns></returns>w
        public ClassifiedAdWithDetail GetClassifiedAdWithDetails(string stringId)
        {
            // Check for session id
            var ad = CurrentDbContext.ClassifiedDB.ProjectTo <ClassifiedAdWithDetail>().FirstOrDefault(x => x.StringId == stringId);

            if (ad != null)
            {
                ad.SeoCategory = SeoManager.GetSeoCategory(ad.Category.Id, ad.SubCategory.Id);
                ad.SeoLocation = SeoManager.GetSeoLocation(ad.Country.Id, ad.Region.Id);
            }
            return(ad);
        }
Ejemplo n.º 3
0
        public RegionBase EditRegion(RegionEdit editItem)
        {
            var o = CurrentDbContext.RegionDB.Include("Country").SingleOrDefault(r => r.Id == editItem.Id);

            if (o != null)
            {
                o.Name    = editItem.Name;
                o.Lat     = editItem.Lat;
                o.Lng     = editItem.Lng;
                o.Zoom    = editItem.Zoom;
                o.SeoName = SeoManager.GetSeoLocation(o.Country.Name, o.Name);
                CurrentDbContext.SaveChanges();
            }

            return((o == null) ? null : Mapper.Map <RegionBase>(editItem));
        }
Ejemplo n.º 4
0
        public RegionBase AddRegion(RegionAdd newItem)
        {
            // get associated object
            var o = CurrentDbContext.CountryDB.Include("Regions").SingleOrDefault(a => a.Id == newItem.CountryId);

            if (o == null)
            {
                return(Mapper.Map <RegionBase>(newItem));
            }

            // check for duplicate region
            var dup = o.Regions.SingleOrDefault(a => a.Name == newItem.Name);

            if (!o.Regions.Any(a => a.Name == newItem.Name))
            {
                var addedItem = CurrentDbContext.RegionDB.Add(Mapper.Map <Region>(newItem));
                addedItem.Country = o;
                addedItem.SeoName = SeoManager.GetSeoLocation(addedItem.Country.Name, addedItem.Name);
                o.RegionCount++;
                CurrentDbContext.SaveChanges();
                return((addedItem == null) ? null : Mapper.Map <RegionBase>(addedItem));
            }
            return(Mapper.Map <RegionBase>(newItem));
        }