Exemplo n.º 1
0
 public void RemovePin(Contracts.DTO.Pin pin)
 {
     if (pin == null)
     {
         throw new ArgumentException("Pin must be non-null");
     }
     else
     {
         var entity = this._pins.Where(p => p.PinId == pin.PinId).FirstOrDefault();
         if (entity == null)
         {
             throw new ArgumentException(string.Format("{0} was not found", pin.PinId));
         }
         else
         {
             this._pins.Remove(entity);
         }
     }
 }
Exemplo n.º 2
0
        public Contracts.DTO.Pin AddPin(Contracts.DTO.Pin pin)
        {
            if (pin == null)
            {
                throw new ArgumentException("Pin must be non-null");
            }
            else if (pin.PinId != null)
            {
                throw new ArgumentException("Pin ID is not null, ID values cannot be specified");
            }
            else if (pin.Latitude == null || pin.Longitude == null || pin.Name == null)
            {
                throw new ArgumentException("A pin must have a valid latitude, longitude, and name");
            }
            else
            {
                var user = this._users.Where(u => u.UserId == pin.BelongsTo).FirstOrDefault();
                if (user == null)
                {
                    throw new ArgumentException(string.Format("User {0} is invalid", pin.BelongsTo));
                }
                else
                {
                    var id = Guid.NewGuid().ToString();
                    this._pins.Add(new Models.Pin()
                    {
                        PinId     = id,
                        Latitude  = pin.Latitude.Value,
                        Longitude = pin.Longitude.Value,
                        Name      = pin.Name,
                        User      = user
                    });

                    pin.PinId = id;
                    return(pin);
                }
            }
        }
Exemplo n.º 3
0
        public ICollection <Contracts.DTO.Note> FindNotes(Contracts.DTO.Pin pin)
        {
            if (pin == null)
            {
                throw new ArgumentException("The pin cannot be null");
            }
            var pentity = this._pins.Where(p => p.PinId == pin.PinId).FirstOrDefault();

            if (pentity != null)
            {
                if (pentity.Notes != null && pentity.Notes.Count > 0)
                {
                    return(pentity.Notes.Select(n => new Contracts.DTO.Note()
                    {
                        NoteId = n.NoteId,
                        Added = n.Added,
                        BelongsTo = n.Pin.User.UserId,
                        Content = n.Content
                    }).ToList <Contracts.DTO.Note>());
                }
            }

            return(new List <Contracts.DTO.Note>());
        }