protected override byte[] GetItem(byte[] id) { using (var rep = new CarRep()) { var conv = new ModelsForWpf.Converter <ModelsForWpf.Car>(); var us = new Car(conv.ByteArrayToObject(id)); return(conv.ObjectToByteArray(Converter.ToCar(rep.GetItem(us.Id)))); } }
protected override async Task Delete(byte[] id) { using (var rep = new CarRep()) { var conv = new ModelsForWpf.Converter <ModelsForWpf.Car>(); var us = new Car(conv.ByteArrayToObject(id)); await rep.Delete(us.Id); } }
protected override async Task Update(byte[] item) { using (var rep = new CarRep()) { var conv = new ModelsForWpf.Converter <ModelsForWpf.Car>(); var us = new Car(conv.ByteArrayToObject(item)); await rep.Update(us); await rep.Save(); } }
static public ModelsForWpf.Talon ToTalon(Talon talon) { var ret = new ModelsForWpf.Talon(talon.Id, talon.One, talon.Two, null, null); using (var rep = new CarRep()) ret.Car = ToCar(rep.GetItem(talon?.Car_Id ?? -1)); using (var rep = new SlotRep()) ret.Slot = ToSlot(rep.GetItem(talon?.Slot_Id ?? -1)); return(ret); }
protected override byte[] GetItems() { using (var rep = new CarRep()) { var conv = new ModelsForWpf.Converter <List <ModelsForWpf.Car> >(); var lst = new List <ModelsForWpf.Car>(); foreach (var u in rep.GetItems()) { lst.Add(Converter.ToCar(u)); } return(conv.ObjectToByteArray(lst)); } }
protected override async Task Create(byte[] item) { using (var uc = new UserCarRep()) using (var rep = new CarRep()) { var conv = new ModelsForWpf.Converter <ModelsForWpf.Car>(); var temp = conv.ByteArrayToObject(item); var us = new Car(temp); await rep.Create(us); await rep.Save(); foreach (var c in rep.GetItems()) { if (c.RegNum == us.RegNum) { await uc.Create(new UserCars(0, temp.Owner.Id, c.Id)); } } } }
static public ModelsForWpf.User ToUser(User user) { var ret = new ModelsForWpf.User(); ret.Id = user.Id; ret.IsAdmin = user.IsAdmin; ret.PhoneNum = user.PhoneNum; ret.Password = user.Password; ret.Login = user.Login; ret.FullName = user.FullName; ret.Cars = new List <ModelsForWpf.Car>(); using (var userCarRep = new UserCarRep()) using (var carRep = new CarRep()) { foreach (var uc in userCarRep.GetItems()) { if (uc.Owner_Id == ret.Id) { ret.Cars.Add(ToCar(carRep.GetItem(uc.Car_Id), ret)); } } } return(ret); }
public CarController() { mapperCar = new MapperCar(); repCar = new CarRep(); }