Exemplo n.º 1
0
        public IRoom AddInhabitant(int roomId, IResident dweller)
        {
            var room = _db.Rooms.Where(r => r.Id == roomId).FirstOrDefault();
            if (room == null)
                return null;

            Resident res = _db.Residents.Where(r => r.Id == dweller.Id).FirstOrDefault();

            if (res != null)
            {
                //if (!room.Inhabitants.Contains(res))
                    room.Inhabitants.Add(res);
            } else
            {
                //var res2 = AddResident(dweller);
                res = new Resident()
                {
                    Id = dweller.Id,
                    JobDescription = dweller.JobDescription,
                    LastName = dweller.LastName,
                    Name = dweller.Name,
                    Title = dweller.Title
                };
                room.Inhabitants.Add(res);
            }
            _db.SaveChanges();

            return room;
        }
Exemplo n.º 2
0
        public IResident AddResident(IResident dweller)
        {
            if (dweller == null)
                return null;

            var res = new Resident()
            {
                JobDescription = dweller.JobDescription,
                LastName = dweller.LastName,
                Name = dweller.Name,
                Title = dweller.Title
            };

            _db.Residents.Add(res);
            _db.SaveChanges();
            return res;
        }
Exemplo n.º 3
0
        public IResident EditResident(IResident r)
        {
            var res = _db.Residents.Where(re => re.Id == r.Id).FirstOrDefault();

            if (res == null)
                return null;

            var resident = new Resident()
            {
                Id = res.Id,
                JobDescription = r.JobDescription,
                LastName = r.LastName,
                Name = r.Name,
                Title = r.Title
            };

            _db.Residents.AddOrUpdate(resident);
            _db.SaveChanges();
            return resident;
        }