public bool AddPet(IPet pet) { using (IDal dal = new ProtoDBContext()) { var mapper = new ProtoPetMap(dal); var dbmodel = mapper.Map(pet as IModel); return dal.AddPet(dbmodel as ProtoPetModel); } }
public bool? AddPet(AddPetMessage message) { using (IDal dal = new ProtoDBContext()) { var user = dal.GetUserByName(Thread.CurrentPrincipal.Identity.Name); if (user == null) return null; if (user.ID != message.UserId) return null; var petmapper = new ProtoPetMap(dal); return dal.AddPet(petmapper.Map(message.Model) as IPet); } }
public IEnumerable<IModel> GetPets() { using (IDal dal = new ProtoDBContext()) { var data = dal.GetPets().ToList(); var pets = new List<IModel>(); var mapper = new ProtoPetMap(dal); foreach (var pet in data) { var petModel = mapper.Map(pet as IDBModel); pets.Add(petModel); } return pets; } }
public IModel GetUser(Guid id) { using (IDal dal = new ProtoDBContext()) { var data = dal.GetUserById(id); var userModel = new ProtoUserMap(dal).Map(data as IDBModel) as UserModel; var pets = new List<IPet>(); var petmapper = new ProtoPetMap(dal); foreach (var pet in userModel.Pets) { pets.Add(petmapper.Map(pet as IDBModel) as IPet); } userModel.Pets = pets; return userModel; } }
public List<IModel> GetUsers() { using (IDal dal = new ProtoDBContext()) { var data = dal.GetUsers().ToList(); var users = new List<IModel>(); var mapper = new ProtoUserMap(dal); var petmapper = new ProtoPetMap(dal); foreach (var user in data) { var userModel = mapper.Map(user as IDBModel) as UserModel; var pets = new List<IPet>(); foreach (var pet in userModel.Pets) { pets.Add(petmapper.Map(pet as IDBModel) as IPet); } userModel.Pets = pets; users.Add(userModel); } return users; } }