コード例 #1
0
 public CustomerModelResponse GetCustomer(int id)
 {
     using (DataLayer.DataAccess.Context context = new DataLayer.DataAccess.Context())
     {
         Customer customer = context.Customers.Find(id);
         return(new CustomerModelResponse(customer));
     }
 }
コード例 #2
0
ファイル: PhoneServices.cs プロジェクト: Orics/KShop
 public IEnumerable <PhoneModelResponse> GetAllPhones()
 {
     using (DataLayer.DataAccess.Context context = new DataLayer.DataAccess.Context()) {
         List <PhoneModelResponse> list = new List <PhoneModelResponse>();
         foreach (Phone phone in context.Products.OfType <Phone>().ToArray())
         {
             list.Add(
                 new PhoneModelResponse(phone)
                 );
         }
         return(list);
     }
 }
コード例 #3
0
 public bool DeleteCustomer(int id)
 {
     using (DataLayer.DataAccess.Context context = new DataLayer.DataAccess.Context())
     {
         Customer customer = context.Customers.First(c => c.Id == id);
         if (customer != null)
         {
             context.Customers.Remove(customer);
             context.SaveChanges();
             return(true);
         }
         return(false);
     }
 }
コード例 #4
0
 public IEnumerable <CustomerModelResponse> GetAllCustomers()
 {
     using (DataLayer.DataAccess.Context context = new DataLayer.DataAccess.Context())
     {
         List <CustomerModelResponse> list = new List <CustomerModelResponse>();
         foreach (Customer customer in context.Customers.ToArray())
         {
             list.Add(
                 new CustomerModelResponse(customer)
                 );
         }
         return(list);
     }
 }
コード例 #5
0
ファイル: PhoneServices.cs プロジェクト: Orics/KShop
 public PhoneModelResponse GetPhone(int id)
 {
     using (DataLayer.DataAccess.Context context = new DataLayer.DataAccess.Context())
     {
         var phone = context.Products.OfType <Phone>().First(p => p.Id == id);
         if (phone != null)
         {
             return(new PhoneModelResponse(phone));
         }
         else
         {
             return(null);
         }
     }
 }
コード例 #6
0
        public int CreateCustomer(CustomerModelResquest data)
        {
            if (data != null && data.IsValidate())
            {
                Customer customer = data.ToCustomer();
                using (DataLayer.DataAccess.Context context = new DataLayer.DataAccess.Context())
                {
                    context.Customers.Add(customer);

                    context.SaveChanges();

                    return(customer.Id);
                }
            }
            return(0);
        }
コード例 #7
0
ファイル: PhoneServices.cs プロジェクト: Orics/KShop
        public int CreatePhone(PhoneModelRequest data)
        {
            if (data != null && data.IsValidate())
            {
                Phone phone = data.ToPhone();
                using (DataLayer.DataAccess.Context context = new DataLayer.DataAccess.Context())
                {
                    context.Products.Add(phone);

                    context.SaveChanges();

                    return(phone.Id);
                }
            }
            return(0);
        }
コード例 #8
0
 public List <PhoneModelResponse> GetAllPhonesOfProduction(int id)
 {
     using (DataLayer.DataAccess.Context context = new DataLayer.DataAccess.Context()) {
         List <PhoneModelResponse> list = new List <PhoneModelResponse>();
         var products = context.Productions.Include(p => p.Products).First(p => p.Id == id).Products;
         if (products != null)
         {
             foreach (Phone phone in products)
             {
                 list.Add(
                     new PhoneModelResponse(phone)
                     );
             }
         }
         return(list);
     }
 }
コード例 #9
0
 public bool UpdateCustomer(int id, CustomerModelResquest data)
 {
     if (data != null && data.IsValidate())
     {
         using (DataLayer.DataAccess.Context context = new DataLayer.DataAccess.Context())
         {
             Customer customer = context.Customers.First(c => c.Id == id);
             if (customer != null)
             {
                 customer.FirstName = data.FirstName;
                 customer.LastName  = data.LastName;
                 customer.Email     = data.Email;
             }
             context.SaveChanges();
             return(true);
         }
     }
     return(false);
 }
コード例 #10
0
ファイル: PhoneServices.cs プロジェクト: Orics/KShop
        public bool UpdatePhone(int id, PhoneModelRequest data)
        {
            if (data != null && data.IsValidate())
            {
                using (DataLayer.DataAccess.Context context = new DataLayer.DataAccess.Context())
                {
                    Phone phone = context.Products.OfType <Phone>().First(p => p.Id == id);

                    if (phone != null)
                    {
                        //update data
                    }

                    context.SaveChanges();

                    return(true);
                }
            }
            return(false);
        }