private Request CreateModel(RequestBindingModel model, Request request, CTODatabase context) { request.ClientId = model.ClientId; request.RequestName = model.RequestName; request.RequestCost = model.RequestCost; request.DateFrom = model.DateFrom; request.DateTo = model.DateTo; if (model.Id.HasValue) { var requestWorks = context.RequestWorks.Where(rec => rec.RequestId == model.Id.Value).ToList(); context.RequestWorks.RemoveRange(requestWorks.Where(rec => !model.RequestWorks.ContainsKey(rec.WorkId)).ToList()); context.SaveChanges(); foreach (var updateComponent in requestWorks) { model.RequestWorks.Remove(updateComponent.WorkId); } context.SaveChanges(); } foreach (var pc in model.RequestWorks) { context.RequestWorks.Add(new RequestWork { RequestId = request.Id, WorkId = pc.Key, }); context.SaveChanges(); } return(request); }
public List <WorkViewModel> GetFullList() { using (var context = new CTODatabase()) { return(context.Works.Select(CreateViewModel).ToList()); } }
public void Update(RequestBindingModel model) { using (var context = new CTODatabase()) { using (var transaction = context.Database.BeginTransaction()) { try { var element = context.Requests.Include(rec => rec.RequestWorks) .ThenInclude(rec => rec.Work).FirstOrDefault(rec => rec.Id == model.Id); if (element == null) { throw new Exception("Заявка не найдена"); } CreateModel(model, element, context); context.SaveChanges(); transaction.Commit(); } catch { transaction.Rollback(); throw; } } } }
public RequestViewModel GetElement(RequestBindingModel model) { if (model == null) { return(null); } using (var context = new CTODatabase()) { var request = context.Requests .Include(rec => rec.RequestWorks) .ThenInclude(rec => rec.Request) .FirstOrDefault(rec => rec.RequestName == model.RequestName || rec.Id == model.Id); return(request != null ? new RequestViewModel { Id = request.Id, ClientId = request.ClientId, RequestName = request.RequestName, RequestCost = request.RequestCost, DateFrom = request.DateFrom, DateTo = request.DateTo, } : null); } }
public void Insert(CostBindingModel model) { using (var context = new CTODatabase()) { context.Costs.Add(CreateModel(model, new Cost())); context.SaveChanges(); } }
public void Insert(WorkBindingModel model) { using (var context = new CTODatabase()) { context.Works.Add(CreateModel(model, new Work())); context.SaveChanges(); } }
public List <PaymentViewModel> GetFullList() { using (var context = new CTODatabase()) { return(context.Payments.Include(rec => rec.Client) .Include(rec => rec.Work) .Select(CreateViewModel) .ToList()); } }
public List <CostViewModel> GetFullList() { using (var context = new CTODatabase()) { return(context.Costs .Include(rec => rec.RequestCost) .ThenInclude(rec => rec.Request) .Select(CreateViewModel) .ToList()); } }
public void Update(WorkerBindingModel model) { using (var context = new CTODatabase()) { var element = context.Workers.FirstOrDefault(rec => rec.Id == model.Id); if (element == null) { throw new Exception("Сотрудник не найден"); } CreateModel(model, element); context.SaveChanges(); } }
public WorkViewModel GetElement(WorkBindingModel model) { if (model == null) { return(null); } using (var context = new CTODatabase()) { var work = context.Works.Include(rec => rec.Worker) .FirstOrDefault(rec => rec.Id == model.Id || rec.WorkName == model.WorkName); return(work != null?CreateViewModel(work) : null); } }
public void Update(WorkBindingModel model) { using (var context = new CTODatabase()) { var element = context.Works.FirstOrDefault(rec => rec.Id == model.Id); if (element == null) { throw new Exception("Такого ремонта нет"); } CreateModel(model, element); context.SaveChanges(); } }
public void Update(CostBindingModel model) { using (var context = new CTODatabase()) { var element = context.Costs.FirstOrDefault(rec => rec.Id == model.Id); if (element == null) { throw new Exception("Статья затрат не найдена"); } CreateModel(model, element); context.SaveChanges(); } }
public List <PaymentViewModel> GetFilteredList(PaymentBindingModel model) { if (model == null) { return(null); } using (var context = new CTODatabase()) { return(context.Payments.Where(rec => rec.Id == model.Id).Include(rec => rec.Client) .Include(rec => rec.Work) .Select(CreateViewModel) .ToList()); } }
public List <ClientViewModel> GetFullList() { using (var context = new CTODatabase()) { return(context.Clients.Select(rec => new ClientViewModel { Id = rec.Id, FIO = rec.FIO, Email = rec.Email, Password = rec.Password, NumberPhone = rec.NumberPhone }) .ToList()); } }
public void Delete(CostBindingModel model) { using (var context = new CTODatabase()) { Cost element = context.Costs.FirstOrDefault(rec => rec.Id == model.Id); if (element != null) { context.Costs.Remove(element); context.SaveChanges(); } else { throw new Exception("Статья затрат не найдена"); } } }
public void Delete(WorkerBindingModel model) { using (var context = new CTODatabase()) { Worker element = context.Workers.FirstOrDefault(rec => rec.Id == model.Id); if (element != null) { context.Workers.Remove(element); context.SaveChanges(); } else { throw new Exception("Сотрудник не найден"); } } }
public void Delete(WorkBindingModel model) { using (var context = new CTODatabase()) { Work element = context.Works.FirstOrDefault(rec => rec.Id == model.Id); if (element != null) { context.Works.Remove(element); context.SaveChanges(); } else { throw new Exception("Такого ремонта нет"); } } }
public void Delete(RequestBindingModel model) { using (var context = new CTODatabase()) { Request element = context.Requests.Include(rec => rec.RequestWorks) .ThenInclude(rec => rec.Work).FirstOrDefault(rec => rec.Id == model.Id); if (element != null) { context.Requests.Remove(element); context.SaveChanges(); } else { throw new Exception("Заявка не найдена"); } } }
public List <WorkViewModel> GetFilteredList(WorkBindingModel model) { if (model == null) { return(null); } using (var context = new CTODatabase()) { return(context.Works.Include(rec => rec.Worker) .Select(rec => new WorkViewModel { Id = rec.Id, WorkerId = rec.WorkerId, WorkName = rec.WorkName, WorkPrice = rec.WorkPrice }) .ToList()); } }
public List <ClientViewModel> GetFilteredList(ClientBindingModel model) { if (model == null) { return(null); } using (var context = new CTODatabase()) { return(context.Clients.Where(rec => rec.Email == model.Email && rec.Password == rec.Password) .Select(rec => new ClientViewModel { Id = rec.Id, FIO = rec.FIO, NumberPhone = rec.NumberPhone, Email = rec.Email, Password = rec.Password }) .ToList()); } }
public List <RequestViewModel> GetFilteredList(RequestBindingModel model) { if (model == null) { return(null); } using (var context = new CTODatabase()) { return(context.Requests .Include(rec => rec.RequestWorks) .ThenInclude(rec => rec.Work) .Include(rec => rec.Client) .Include(rec => rec.RequestCosts) .ThenInclude(rec => rec.Cost) .Where(rec => model.DateFrom.HasValue && model.DateTo.HasValue && rec.ClientId == model.ClientId || !model.DateFrom.HasValue && !model.DateTo.HasValue && rec.ClientId == model.ClientId) .Select(CreateViewModel) .ToList()); } }
public List <CostViewModel> GetFilteredList(CostBindingModel model) { if (model == null) { return(null); } using (var context = new CTODatabase()) { return(context.Costs.Include(rec => rec.Worker).Where(rec => rec.Id == model.Id || rec.WorkerId == model.WorkerId) .Select(rec => new CostViewModel { Id = rec.Id, WorkerId = rec.WorkerId, CostName = rec.CostName, CostPrice = rec.CostPrice }) .ToList()); } }
public CostViewModel GetElement(CostBindingModel model) { if (model == null) { return(null); } using (var context = new CTODatabase()) { var cost = context.Costs.Include(rec => rec.Worker).FirstOrDefault(rec => rec.Id == model.Id); return(cost != null ? new CostViewModel { Id = cost.Id, WorkerId = cost.WorkerId, CostName = cost.CostName, CostPrice = cost.CostPrice } : null); } }
public WorkerViewModel GetElement(WorkerBindingModel model) { if (model == null) { return(null); } using (var context = new CTODatabase()) { var worker = context.Workers.FirstOrDefault(rec => rec.Id == model.Id || rec.Email == model.Email); return(worker != null ? new WorkerViewModel { Id = worker.Id, FIO = worker.FIO, NumberPhone = worker.NumberPhone, Email = worker.Email, Password = worker.Password } : null); } }
public ClientViewModel GetElement(ClientBindingModel model) { if (model == null) { return(null); } using (var context = new CTODatabase()) { var client = context.Clients.FirstOrDefault(rec => rec.Id == model.Id || rec.Email == model.Email); return(client != null ? new ClientViewModel { Id = client.Id, FIO = client.FIO, NumberPhone = client.NumberPhone, Email = client.Email, Password = client.Password } : null); } }
public void Insert(RequestBindingModel model) { using (var context = new CTODatabase()) { using (var transaction = context.Database.BeginTransaction()) { try { Request request = CreateModel(model, new Request()); context.Requests.Add(request); context.SaveChanges(); CreateModel(model, request, context); transaction.Commit(); } catch { transaction.Rollback(); throw; } } } }
public PaymentViewModel GetElement(PaymentBindingModel model) { if (model == null) { return(null); } using (var context = new CTODatabase()) { var payment = context.Payments.Include(rec => rec.Client) .Include(rec => rec.Work).FirstOrDefault(rec => rec.ClientId == model.ClientId); return(payment != null ? new PaymentViewModel { Id = payment.Id, ClientId = payment.ClientId, WorkId = payment.WorkId, WorkName = payment.Work.WorkName, Sum = payment.Sum, DateOfPayment = payment.DateOfPayment } : null); } }