Beispiel #1
0
 public void SaveProject(Project project)
 {
     using (var dbContext = new CrmDbContext())
     {
         if (project.ID > 0)
         {
             dbContext.Update<Project>(project);
         }
         else
         {
             dbContext.Insert<Project>(project);
         }
     }
 }
Beispiel #2
0
 public void SaveVisitRecord(VisitRecord visitRecord)
 {
     using (var dbContext = new CrmDbContext())
     {
         if (visitRecord.ID > 0)
         {
             dbContext.Update<VisitRecord>(visitRecord);
         }
         else
         {
             dbContext.Insert<VisitRecord>(visitRecord);
         }
     }
 }
Beispiel #3
0
        public void SaveCustomer(Customer customer)
        {
            using (var dbContext = new CrmDbContext())
            {
                if (customer.ID > 0)
                {
                    if (dbContext.Customers.Any(c => c.Tel == customer.Tel && c.ID != customer.ID))
                        throw new BusinessException("Tel", "已存在此电话的客户!");

                    if (dbContext.Customers.Any(c => c.Number == customer.Number && c.ID != customer.ID))
                        throw new BusinessException("Number", "已存在此编号的客户!");
                    
                    dbContext.Update<Customer>(customer);
                }
                else
                {
                    if (dbContext.Customers.Any(c => c.Tel == customer.Tel))
                        throw new BusinessException("Tel", "已存在此电话的客户!");

                    if (dbContext.Customers.Any(c => c.Number == customer.Number))
                        throw new BusinessException("Number", "已存在此编号的客户!");
                    
                    dbContext.Insert<Customer>(customer);
                }
            }
        }