private Route CreateModel(Route route, RouteBindingModel model, UrskiyPeriodDatabase context) { route = CreateModel(route, model); if (model.Id.HasValue) { var routeReserve = context.RouteReserves.Where(rec => rec.RouteId == model.Id.Value).ToList(); // удаляем те, которых нет в модели context.RouteReserves.RemoveRange(routeReserve.Where(rec => !model.RouteReverces.ContainsKey(rec.ReserveId)).ToList()); context.SaveChanges(); foreach (var Reserve in routeReserve) { model.RouteReverces.Remove(Reserve.ReserveId); } } foreach (var routeReserve in model.RouteReverces) { context.RouteReserves.Add(new RouteReserve { ReserveId = routeReserve.Key, RouteId = route.Id }); } context.SaveChanges(); return(route); }
public List <ReserveViewModel> GetFullList() { using (var context = new UrskiyPeriodDatabase()) { return(context.Reserves.Include(x => x.Payment).Select(CreateModel).ToList()); } }
public void Update(RouteBindingModel model) { using (var context = new UrskiyPeriodDatabase()) { using (var transaction = context.Database.BeginTransaction()) { try { var route = context.Routes.FirstOrDefault(rec => rec.Id == model.Id); if (route == null) { throw new Exception("Маршрут не найден"); } CreateModel(route, model, context); context.SaveChanges(); transaction.Commit(); } catch { transaction.Rollback(); throw; } } } }
private CostItem CreateModel(CostItem costItem, CostItemBindingModel model, UrskiyPeriodDatabase context) { costItem = CreateModel(costItem, model); if (model.Id.HasValue) { var routeCost = context.CostItemRoutes.Where(rec => rec.CostItemId == model.Id.Value).ToList(); // удаляем те, которых нет в модели context.CostItemRoutes.RemoveRange(routeCost.Where(rec => !model.CostItemRoute.ContainsKey(rec.RouteId)).ToList()); context.SaveChanges(); foreach (var Reserve in routeCost) { model.CostItemRoute.Remove(Reserve.RouteId); } } foreach (var cost in model.CostItemRoute) { context.CostItemRoutes.Add(new CostItemRoute { CostItemId = costItem.Id, RouteId = cost.Key }); } context.SaveChanges(); return(costItem); }
public List <PaymentViewModel> GetFullList() { using (var context = new UrskiyPeriodDatabase()) { return(context.Payment.Select(CreateModel).ToList()); } }
public void Update(CostItemBindingModel model) { using (var context = new UrskiyPeriodDatabase()) { using (var transaction = context.Database.BeginTransaction()) { try { var costItem = context.CostItem.FirstOrDefault(rec => rec.Id == model.Id); if (costItem == null) { throw new Exception("Не найдено"); } CreateModel(costItem, model, context); context.SaveChanges(); transaction.Commit(); } catch { transaction.Rollback(); throw; } } } }
public void Insert(RouteBindingModel model) { using (var context = new UrskiyPeriodDatabase()) { using (var transaction = context.Database.BeginTransaction()) { try { if (context.Routes.FirstOrDefault(rec => rec.Name == model.Name) != null) { return; } Route route = CreateModel(new Route(), model); context.Routes.Add(route); context.SaveChanges(); CreateModel(route, model, context); transaction.Commit(); } catch { transaction.Rollback(); throw; } } } }
public int Count() { using (var context = new UrskiyPeriodDatabase()) { return(context.CostItem.Count()); } }
public void Insert(UserBindingModel model) { using (var context = new UrskiyPeriodDatabase()) { context.Users.Add(CreateModel(new User(), model)); context.SaveChanges(); } }
public void Insert(PaymentBindingModel model) { using (var context = new UrskiyPeriodDatabase()) { context.Payment.Add(CreateModel(new Payment(), model)); context.SaveChanges(); } }
public List <RouteViewModel> GetFullList() { using (var context = new UrskiyPeriodDatabase()) { return(context.Routes.Include(x => x.User).Include(x => x.RouteReserve).ThenInclude(x => x.Reserve) .ThenInclude(x => x.Payment) .Include(x => x.CostItemRoute).ThenInclude(x => x.CostItem) .Select(CreateModel).ToList()); } }
public List <UserViewModel> GetFilteredList(UserBindingModel model) { if (model == null) { return(null); } using (var context = new UrskiyPeriodDatabase()) { return(context.Users.Where(rec => rec.Login == model.Login).Select(CreateModel).ToList()); } }
public List <PaymentViewModel> GetFilteredList(PaymentBindingModel model) { if (model == null) { return(null); } using (var context = new UrskiyPeriodDatabase()) { return(context.Payment.Where(rec => rec.Sum == model.Sum).Select(CreateModel).ToList()); } }
public List <ReserveViewModel> GetFilteredList(ReserveBindingModel model) { if (model == null) { return(null); } using (var context = new UrskiyPeriodDatabase()) { return(context.Reserves.Include(x => x.Payment) .Where(rec => rec.RouteReserve.Select(x => x.RouteId).Contains(model.RouteId)).Select(CreateModel).ToList()); } }
public void Insert(ReserveBindingModel model) { using (var context = new UrskiyPeriodDatabase()) { if (context.Reserves.FirstOrDefault(rec => rec.Name == model.Name) != null) { return; } context.Reserves.Add(CreateModel(new Reserve(), model)); context.SaveChanges(); } }
public PaymentViewModel GetElement(PaymentBindingModel model) { if (model == null) { return(null); } using (var context = new UrskiyPeriodDatabase()) { var route = context.Payment.FirstOrDefault(rec => rec.Id == model.Id); return(route != null?CreateModel(route) : null); } }
public void Update(UserBindingModel model) { using (var context = new UrskiyPeriodDatabase()) { var user = context.Users.FirstOrDefault(rec => rec.Id == model.Id); if (user == null) { throw new Exception("Клиент не найден"); } CreateModel(user, model); context.SaveChanges(); } }
public void Delete(ReserveBindingModel model) { using (var context = new UrskiyPeriodDatabase()) { var user = context.Reserves.FirstOrDefault(rec => rec.Id == model.Id); if (user == null) { throw new Exception("Заповедник не найден"); } context.Reserves.Remove(user); context.SaveChanges(); } }
public ReserveViewModel GetElement(ReserveBindingModel model) { if (model == null) { return(null); } using (var context = new UrskiyPeriodDatabase()) { var route = context.Reserves.Include(x => x.Payment) .FirstOrDefault(rec => rec.Id == model.Id || rec.Name == model.Name); return(route != null?CreateModel(route) : null); } }
public void Delete(RouteBindingModel model) { using (var context = new UrskiyPeriodDatabase()) { var route = context.Routes.FirstOrDefault(rec => rec.Id == model.Id); if (route == null) { throw new Exception("Маршрут не найден"); } context.Routes.Remove(route); context.SaveChanges(); } }
public void Delete(PaymentBindingModel model) { using (var context = new UrskiyPeriodDatabase()) { var user = context.Payment.FirstOrDefault(rec => rec.Id == model.Id); if (user == null) { throw new Exception("Не найдено"); } context.Payment.Remove(user); context.SaveChanges(); } }
public void Update(PaymentBindingModel model) { using (var context = new UrskiyPeriodDatabase()) { var payment = context.Payment.FirstOrDefault(rec => rec.Id == model.Id); if (payment == null) { throw new Exception("Не найдено"); } CreateModel(payment, model); context.SaveChanges(); } }
public CostItemViewModel GetElement(CostItemBindingModel model) { using (var context = new UrskiyPeriodDatabase()) { var costItem = context.CostItem.Include(x => x.CostItemRoute).ThenInclude(x => x.Route) .FirstOrDefault(rec => rec.Id == model.Id || rec.Name == model.Name); return(costItem != null ? new CostItemViewModel { Id = costItem.Id, Name = costItem.Name, Sum = costItem.Sum, CostItemRoute = costItem.CostItemRoute.ToDictionary(x => x.RouteId, x => x.Route.Name) } : null); } }
public List <RouteViewModel> GetFilteredList(RouteBindingModel model) { using (var context = new UrskiyPeriodDatabase()) { return(context.Routes.Include(x => x.User).Include(x => x.RouteReserve).ThenInclude(x => x.Reserve) .ThenInclude(x => x.Payment) .Include(x => x.CostItemRoute).ThenInclude(x => x.CostItem) .Where(rec => // сортируем по клиенту (model.UserId.HasValue && !model.DateFrom.HasValue && model.PickedRoutes == null && model.UserId == rec.UserId) || // маршруты без статей затрат для заполнения бд (!model.DateFrom.HasValue && model.PickedRoutes == null && !model.UserId.HasValue && model.NoCost.HasValue && model.NoCost.Value && rec.CostItemRoute.Count == 0)) .ToList().Select(CreateModel).ToList()); } }
public UserViewModel GetElement(UserBindingModel model) { if (model == null) { return(null); } using (var context = new UrskiyPeriodDatabase()) { var user = context.Users.FirstOrDefault(rec => rec.Id == model.Id || rec.Email == model.Email || rec.Login == model.Login); if (user == null || (model.Password != null && user.Password != model.Password)) { return(null); } return(CreateModel(user)); } }
public List <RouteViewModel> GetFilteredByPickList(RouteBindingModel model) { using (var context = new UrskiyPeriodDatabase()) { return(context.Routes.Include(x => x.User).Include(x => x.RouteReserve).ThenInclude(x => x.Reserve) .Where(x => model.PickedRoutes.Contains(x.Id)).Select(x => new RouteViewModel { Reserves = x.RouteReserve.Select(rec => new ReserveViewModel { Name = rec.Reserve.Name, Price = rec.Reserve.Price }).ToList(), Name = x.Name, Cost = x.Cost }).ToList()); } }
public List <RouteViewModel> GetFilteredByDateList(RouteBindingModel model) { using (var context = new UrskiyPeriodDatabase()) { return(context.Routes.Include(x => x.User).Include(x => x.CostItemRoute).ThenInclude(x => x.CostItem) .Where(rec => model.DateFrom.HasValue && model.DateFrom.HasValue && model.DateFrom.Value.Date <= rec.DateVisit.Date && rec.DateVisit.Date <= model.DateTo.Value.Date && model.UserId == rec.UserId) .Select(x => new RouteViewModel { CostItems = x.CostItemRoute.Select(rec => new CostItemViewModel { Name = rec.CostItem.Name, Sum = rec.CostItem.Sum }).ToList(), Name = x.Name, Cost = x.Cost, DateVisit = x.DateVisit, Count = x.Count }).ToList()); } }
public void Insert(CostItemBindingModel model) { using (var context = new UrskiyPeriodDatabase()) { using (var transaction = context.Database.BeginTransaction()) { try { CostItem cost = CreateModel(new CostItem(), model); context.CostItem.Add(cost); context.SaveChanges(); CreateModel(cost, model, context); context.SaveChanges(); transaction.Commit(); } catch { transaction.Rollback(); throw; } } } }