コード例 #1
0
ファイル: RequestStorage.cs プロジェクト: Unforgettable01/CTO
        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);
        }
コード例 #2
0
 public List <WorkViewModel> GetFullList()
 {
     using (var context = new CTODatabase())
     {
         return(context.Works.Select(CreateViewModel).ToList());
     }
 }
コード例 #3
0
ファイル: RequestStorage.cs プロジェクト: Unforgettable01/CTO
 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;
             }
         }
     }
 }
コード例 #4
0
ファイル: RequestStorage.cs プロジェクト: Unforgettable01/CTO
 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);
     }
 }
コード例 #5
0
ファイル: CostStorage.cs プロジェクト: Unforgettable01/CTO
 public void Insert(CostBindingModel model)
 {
     using (var context = new CTODatabase())
     {
         context.Costs.Add(CreateModel(model, new Cost()));
         context.SaveChanges();
     }
 }
コード例 #6
0
 public void Insert(WorkBindingModel model)
 {
     using (var context = new CTODatabase())
     {
         context.Works.Add(CreateModel(model, new Work()));
         context.SaveChanges();
     }
 }
コード例 #7
0
ファイル: PaymentStorage.cs プロジェクト: Unforgettable01/CTO
 public List <PaymentViewModel> GetFullList()
 {
     using (var context = new CTODatabase())
     {
         return(context.Payments.Include(rec => rec.Client)
                .Include(rec => rec.Work)
                .Select(CreateViewModel)
                .ToList());
     }
 }
コード例 #8
0
ファイル: CostStorage.cs プロジェクト: Unforgettable01/CTO
 public List <CostViewModel> GetFullList()
 {
     using (var context = new CTODatabase())
     {
         return(context.Costs
                .Include(rec => rec.RequestCost)
                .ThenInclude(rec => rec.Request)
                .Select(CreateViewModel)
                .ToList());
     }
 }
コード例 #9
0
 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();
     }
 }
コード例 #10
0
 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);
     }
 }
コード例 #11
0
 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();
     }
 }
コード例 #12
0
ファイル: CostStorage.cs プロジェクト: Unforgettable01/CTO
 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();
     }
 }
コード例 #13
0
ファイル: PaymentStorage.cs プロジェクト: Unforgettable01/CTO
 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());
     }
 }
コード例 #14
0
ファイル: ClientStorage.cs プロジェクト: Unforgettable01/CTO
 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());
     }
 }
コード例 #15
0
ファイル: CostStorage.cs プロジェクト: Unforgettable01/CTO
 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("Статья затрат не найдена");
         }
     }
 }
コード例 #16
0
 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("Сотрудник не найден");
         }
     }
 }
コード例 #17
0
 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("Такого ремонта нет");
         }
     }
 }
コード例 #18
0
ファイル: RequestStorage.cs プロジェクト: Unforgettable01/CTO
 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("Заявка не найдена");
         }
     }
 }
コード例 #19
0
 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());
     }
 }
コード例 #20
0
ファイル: ClientStorage.cs プロジェクト: Unforgettable01/CTO
 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());
     }
 }
コード例 #21
0
ファイル: RequestStorage.cs プロジェクト: Unforgettable01/CTO
 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());
     }
 }
コード例 #22
0
ファイル: CostStorage.cs プロジェクト: Unforgettable01/CTO
 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());
     }
 }
コード例 #23
0
ファイル: CostStorage.cs プロジェクト: Unforgettable01/CTO
 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);
     }
 }
コード例 #24
0
 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);
     }
 }
コード例 #25
0
ファイル: ClientStorage.cs プロジェクト: Unforgettable01/CTO
 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);
     }
 }
コード例 #26
0
ファイル: RequestStorage.cs プロジェクト: Unforgettable01/CTO
 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;
             }
         }
     }
 }
コード例 #27
0
ファイル: PaymentStorage.cs プロジェクト: Unforgettable01/CTO
 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);
     }
 }