Example #1
0
        public static void AddCustomer(CustomerDTO dto)
        {
            using (var db = new WebDBEntities())
            {
                var customer = new Customer
                {
                    Name = dto.Name,
                    Surname = dto.Surname,
                    Phone = dto.Phone,
                    Email = dto.Email
                };

                db.Customers.Add(customer);

                db.SaveChanges();
            }
        }
Example #2
0
        public static void UpdateCustomer(CustomerDTO customerDto)
        {
            using (var db = new WebDBEntities())
            {
                var customer = db.Customers.FirstOrDefault(r => r.Id == customerDto.Id) ?? new Customer { Id = customerDto.Id };

                customer.Name = customerDto.Name;
                customer.Surname = customerDto.Surname;
                customer.Email = customerDto.Email;
                customer.Phone = customerDto.Phone;

                db.Customers.AddOrUpdate(customer);

                db.SaveChanges();
            }
        }
Example #3
0
        public ActionResult Edit(CustomerDTO customerDto)
        {
            Helper.UpdateCustomer(customerDto);

            return RedirectToAction("Index");
        }
Example #4
0
        public static CustomerDTO GetCustomer(int id)
        {
            using (var db = new WebDBEntities())
            {
                var customer = db.Customers.FirstOrDefault(r => r.Id == id);

                if (customer == null) throw new ArgumentException("Неверное значение параметра", nameof(id));

                var customerDTO = new CustomerDTO
                {
                    Id = customer.Id,
                    Name = customer.Name,
                    Surname = customer.Surname,
                    Phone = customer.Phone,
                    Email = customer.Email
                };

                return customerDTO;
            }
        }
Example #5
0
 public ActionResult Add(CustomerDTO customerDto)
 {
     Helper.AddCustomer(customerDto);
     return RedirectToAction("Index");
 }