示例#1
0
 private void Delete(Place place)
 {
     _context.Places.DeleteObject(new PlaceEntity { Id = place.Id });
     _context.SaveChanges();
 }
示例#2
0
        public void Add(Place place, long userId)
        {
            if (place == null)
            {
                throw new ArgumentNullException("place");
            }

            if (string.IsNullOrEmpty(place.Description.Trim()))
            {
                throw new ArgumentNullException("place.Description");
            }

            if (place.Location == null)
            {
                throw new ArgumentNullException("place.Location");
            }

            // try to set the place page name
            var name = this.GetAscii(place.Description);

            if (!this.IsAvailable(name))
            {
                // if it's not available, try to concat the location to the name
                name = GetAscii(name + place.Location.Description);

                // if it's not available, try to concat a number
                if (!this.IsAvailable(name))
                {
                    name = this.GetAscii(place.Description);
                    int c = 1;

                    while (!this.IsAvailable(name + c))
                    {
                        c++;
                    }

                    name = name + c;
                }
            }

            var placeEntity = new PlaceEntity
            {
                Name = place.Description,
                Description = place.Info,
                Address = place.Address,
                LocationId = place.Location.Id,
                MapUa = place.MapUa,
                MapVa = place.MapVa,
                Phone = place.Phone,
                HowToArrive = place.HowToArrive,
                DateFrom = DateTime.Now,
                IsActive = false,
                Page = name,
                CreatedBy = userId,
            };

            foreach (var s in place.Services)
                placeEntity.Services.Add(new Fulbaso.EntityFramework.PlaceService { Service = (byte)s });

            _context.AddToPlaces(placeEntity);
            _context.SaveChanges();

            place.Id = placeEntity.Id;
            place.Page = placeEntity.Page;

            _context.AddToUserPlaces(new UserPlaceEntity
            {
                PlaceId = place.Id,
                UserId = userId,
                Role = "Owner",
            });
            _context.SaveChanges();
        }
示例#3
0
 public IEnumerable<Tuple<Place, double?>> GetNearest(Place place, int count = 10, double distance = 0)
 {
     return GetNearest(place.MapUa, place.MapVa, count, distance);
 }
示例#4
0
        public void Update(Place place)
        {
            var entity = _context.Places.Where(p => p.Id == place.Id).ToList().First();

            if (string.IsNullOrEmpty(place.Page))
            {
                place.Page = entity.Page;
            }
            else
            {
                this.GetAscii(place.Page);
            }

            entity.Name = place.Description;
            entity.Description = place.Info;
            entity.Address = place.Address;
            entity.LocationId = place.Location.Id;
            entity.MapLocation = place.MapLocation;
            entity.MapUa = place.MapUa;
            entity.MapVa = place.MapVa;
            entity.Phone = place.Phone;
            entity.HowToArrive = place.HowToArrive;
            entity.Page = place.Page;

            while (entity.Services.Any()) _context.DeleteObject(entity.Services.First());
            _context.SaveChanges();

            place.Services.ToList().ForEach(s => entity.Services.Add(new Fulbaso.EntityFramework.PlaceService { Service = (byte)s }));
            _context.SaveChanges();
        }
示例#5
0
        public Place Get(Place place, DateTime day)
        {
            place.CourtsInfo = CourtLogic.Get(_context.Courts.Where(c => c.PlaceId == place.Id));

            var configs = _context.CourtConfigurations.Where(c => c.Court.PlaceId == place.Id).ToList();
            var books = _bookService.GetByPlace(place.Id, day, day.AddDays(1).AddMilliseconds(-1));

            foreach (var c in place.CourtsInfo)
            {
                c.Books = books.Where(cb => cb.Court.Id == c.Id).ToList();
                c.Configuration = CourtConfigurationLogic.Get(configs.Where(cc => cc.CourtId == c.Id).ToList());
            }

            return place;
        }