public void PurchaseProductById(int id) { var userId = Convert.ToInt32(_ctxAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value); Product productEntity = _productRepository.Get(id); if (productEntity == null) { throw new Exception("Invalid Product"); } Purchase purchaseEntity = new Purchase() { Price = productEntity.Price, ProductId = productEntity.Id, UserId = userId }; _purchaseRepository.Add(purchaseEntity); db.SaveChanges(); }
public CustomerModel Add(CustomerModel customer) { Customer customerEntity = _customerRepository.GetByEmail(customer.Email); if (customerEntity != null) { throw new Exception("User Already Exists"); } customerEntity = new Customer() { Name = customer.Name, Email = customer.Email, Password = customer.Password, }; _customerRepository.Add(customerEntity); db.SaveChanges(); customer.Id = customerEntity.Id; return(customer); }