public void CopyToBase(MercType mercType) { mercType.idtype = this.idtype; mercType.name = this.name; mercType.notes = this.notes; mercType.sortno = this.sortno; mercType.inuse = this.inuse; }
public static MercType Add(MercType mercType) { TN db = new TN(); db.MercTypes.Add(mercType); db.SaveChanges(); return(mercType); }
public void CopyFromBase(MercType mercType) { this.idtype = mercType.idtype; this.name = mercType.name; this.notes = mercType.notes; this.sortno = mercType.sortno; this.inuse = mercType.inuse; }
public static MercType Edit(MercType mercType) { TN db = new TN(); MercType oldMercType = db.MercTypes.Where(en => en.idtype == mercType.idtype).FirstOrDefault(); oldMercType.idtype = mercType.idtype; oldMercType.name = mercType.name; oldMercType.notes = mercType.notes; oldMercType.sortno = mercType.sortno; oldMercType.inuse = mercType.inuse; db.SaveChanges(); return(oldMercType); }
public static List <SetupAddrViewModel> ConvertToViewModel(List <SetupAddr> entities) { List <SetupAddrViewModel> viewModels = new List <SetupAddrViewModel>(); List <string> idsetups = entities.Select(mod => { return(mod.idsetup); }).ToList(); List <string> idtypes = entities.Select(mod => { return(mod.idtype); }).ToList(); idsetups = idsetups.Distinct().ToList(); idtypes = idtypes.Distinct().ToList(); TN db = new TN(); List <Setup> setups = db.Setups.Where(en => idsetups.Contains(en.idsetup)).ToList(); List <MercType> mercTypes = db.MercTypes.Where(en => idtypes.Contains(en.idtype.ToString())).ToList(); viewModels = entities.Select(mod => { SetupAddrViewModel viewModel = new SetupAddrViewModel(); viewModel.CopyFromBase(mod); if (setups != null && setups.Count > 0) { List <Setup> tempSetups = setups.Where(en => en.idsetup == viewModel.idsetup).ToList(); Setup tempSetup = (tempSetups != null && tempSetups.Count > 0) ? tempSetups.First() : null; SetupViewModel tempSetupModel = new SetupViewModel(); if (tempSetup != null) { tempSetupModel.CopyFromBase(tempSetup); viewModel.setup = tempSetupModel; } } if (mercTypes != null && mercTypes.Count > 0) { List <MercType> tempMercTypes = mercTypes.Where(en => en.idtype.ToString() == viewModel.idtype).ToList(); MercType tempMercType = (tempMercTypes != null && tempMercTypes.Count > 0) ? tempMercTypes.First() : null; MercTypeViewModel tempMercTypeModel = new MercTypeViewModel(); if (tempMercType != null) { tempMercTypeModel.CopyFromBase(tempMercType); viewModel.merctype = tempMercTypeModel; } } return(viewModel); }).ToList(); return(viewModels); }