Пример #1
0
        public void Delete(Model.Order element)
        {
            using (Database1Entities context = new Database1Entities())
            {
                var elementToDelete = context.Orders.SingleOrDefault(o => o.Id == element.ID);

                context.Orders.Remove(elementToDelete);
                context.SaveChanges();
            }
        }
Пример #2
0
        public void Update(Model.Customer element)
        {
            using (Database1Entities context = new Database1Entities())
            {
                var elementToUpdate = context.Customers.SingleOrDefault(o => o.Id == element.ID);

                elementToUpdate.Name        = element.Name;
                elementToUpdate.Mail        = element.Mail;
                elementToUpdate.PhoneNumber = element.PhoneNumber;
                context.SaveChanges();
            }
        }
Пример #3
0
        public void Create(Model.Customer element)
        {
            using (Database1Entities context = new Database1Entities())
            {
                context.Customers.Add(new Customer()
                {
                    Name        = element.Name,
                    Mail        = element.Mail,
                    PhoneNumber = element.PhoneNumber
                });

                context.SaveChanges();
            }
        }
Пример #4
0
        public IEnumerable <Model.Customer> Read()
        {
            List <Model.Customer> customerList = new List <Model.Customer>();

            using (Database1Entities context = new Database1Entities())
            {
                Mapper mapper = new Mapper();

                foreach (var i in context.Customers.ToList())
                {
                    customerList.Add(mapper.MapToModelCustomer(i));
                }
            }

            return(customerList);
        }
Пример #5
0
        public void Update(Model.Order element)
        {
            using (Database1Entities context = new Database1Entities())
            {
                var elementToUpdate = context.Orders.SingleOrDefault(o => o.Id == element.ID);

                elementToUpdate.Name       = element.Name;
                elementToUpdate.Comments   = element.Comments;
                elementToUpdate.Price      = element.Price;
                elementToUpdate.IsPaid     = element.IsPaid;
                elementToUpdate.Date       = element.Date;
                elementToUpdate.IdCustomer = element.Customer.ID;

                context.SaveChanges();
            }
        }
Пример #6
0
        public IEnumerable <Model.Order> GetOrderListDateFromTo(DateTime dateFrom, DateTime dateTo, int ordersCount)
        {
            List <Model.Order> list = new List <Model.Order>();

            using (Database1Entities context = new Database1Entities())
            {
                var dbList = context.Orders.Where(o => o.Date >= dateFrom && o.Date <= dateTo).OrderByDescending(o => o.Date).ThenByDescending(o => o.Id).Take(ordersCount);

                Mapper map = new Mapper();
                foreach (var i in dbList)
                {
                    var order = map.MapToModelOrder(i);
                    list.Add(order);
                }
                return(list);
            }
        }
Пример #7
0
        public void Create(Model.Order element)
        {
            using (Database1Entities context = new Database1Entities())
            {
                context.Orders.Add(new Order()
                {
                    Name       = element.Name,
                    Comments   = element.Comments,
                    Price      = element.Price,
                    IsPaid     = element.IsPaid,
                    Date       = element.Date,
                    IdCustomer = element.Customer.ID
                });

                context.SaveChanges();
            }
        }