Ejemplo n.º 1
0
 public ServiceResponse <data.models.Customer> CreateCustomer(data.models.Customer customer)
 {
     try
     {
         _db.Customers.Add(customer);
         _db.SaveChanges();
         return(new ServiceResponse <data.models.Customer>
         {
             IsSuccess = true,
             Message = "New customer added",
             Time = DateTime.UtcNow,
             Data = customer
         });
     }
     catch (Exception e)
     {
         return(new ServiceResponse <data.models.Customer>
         {
             IsSuccess = false,
             Message = e.StackTrace,
             Time = DateTime.UtcNow,
             Data = customer
         });
     }
 }
Ejemplo n.º 2
0
 public static web.ViewModels.CustomerModel CustomerDataToCustomerView(data.models.Customer customer)
 {
     return(new web.ViewModels.CustomerModel {
         id = customer.id,
         createdOn = customer.createdOn,
         updatedOn = customer.updatedOn,
         firstName = customer.firstName,
         lastName = customer.lastName,
         primaryAddress = AddressDataToAddressView(customer.primaryAddress)
     });
 }
Ejemplo n.º 3
0
        public ActionResult CreateCustomer([FromBody] CustomerModel customer)
        {
            if (ModelState.IsValid == false)
            {
                return(BadRequest(ModelState));
            }

            _logger.LogInformation("Creating a new customer");
            customer.createdOn = DateTime.UtcNow;
            customer.updatedOn = DateTime.UtcNow;
            data.models.Customer customerData = CustomerMapper.CustomerViewToCustomerData(customer);
            return(Ok(_customerService.CreateCustomerAndReturnResponse(customerData)));
        }
Ejemplo n.º 4
0
        public ServiceResponse <bool> DeleteCustomerAndReturnResponse(int id)
        {
            data.models.Customer targetCustomer = _db.Customers.Find(id);

            if (targetCustomer == null)
            {
                return(ServiceResponse <bool> .Failed(false, "Customer to delete not found"));
            }

            try {
                _db.Customers.Remove(targetCustomer);
                _db.SaveChanges();

                return(ServiceResponse <bool> .Successed(true, "Customer deleted"));
            } catch (Exception e) {
                return(ServiceResponse <bool> .Failed(false, e.StackTrace));
            }
        }
Ejemplo n.º 5
0
        public ServiceResponse <data.models.Customer> CreateCustomerAndReturnResponse(data.models.Customer customer)
        {
            try {
                _db.Customers.Add(customer);
                _db.SaveChanges();

                return(ServiceResponse <data.models.Customer> .Successed(customer, "Customer created"));
            } catch (Exception e) {
                return(ServiceResponse <data.models.Customer> .Failed(customer, e.Message));
            }
        }