public void Add(OrderModel order) { Guard.WhenArgument(order, "order").IsNull().Throw(); var mapped = mapper.Map <OrderModel, Order>(order); this.orders.Add(mapped); unitOfWork.SaveChanges(); }
public void AddNewAddress(string addressText, int userId) { Guard.WhenArgument(addressText, "addressText").IsNull().Throw(); var user = this.userService.GetSpecificUser(userId); AddressModel addressDTO = new AddressModel() { AddressText = addressText, UserId = userId }; this.addresses.Add(this.mapper.Map <AddressModel, Address>(addressDTO)); unitOfWork.SaveChanges(); }
public void AddNewBankCard(string number, DateTime expDate, string holderName, int userId) { Guard.WhenArgument(number, "number").IsNull().Throw(); Guard.WhenArgument(holderName, "holderName").IsNull().Throw(); BankCardModel bankCardDTO = new BankCardModel() { Number = number, ExpirationDate = expDate, Name = holderName, UserId = userId }; this.bankCards.Add(this.mapper.Map <BankCardModel, BankCard>(bankCardDTO)); unitOfWork.SaveChanges(); }
public bool RegisterUser (string userName, string password, string phoneNumber, string firstName = null, string lastName = null, string address = null, string bankCardNumber = null, DateTime?expDate = null, string cardName = null) { Guard.WhenArgument(userName, "userName").IsNullOrEmpty().Throw(); Guard.WhenArgument(password, "password").IsNullOrEmpty().Throw(); Guard.WhenArgument(phoneNumber, "phoneNumber").IsNullOrEmpty().Throw(); try { var hashedPassword = hashing.GetSHA1HashData(password); var userModel = new UserModel() { Username = userName, Password = hashedPassword, PhoneNumber = phoneNumber, FirstName = firstName, LastName = lastName, }; var userToAdd = this.mapper.Map <UserModel, User>(userModel); var user = this.GetSpecificUser(userModel.Username); if (address != string.Empty && address != string.Empty) { var a = new AddressModel() { AddressText = address }; var addressToAdd = this.mapper.Map <AddressModel, Address>(a); userToAdd.Adresses.Add(addressToAdd); } if (bankCardNumber != string.Empty && expDate != null && cardName != string.Empty && bankCardNumber != null && expDate != null && cardName != null) { var c = new BankCardModel() { Number = bankCardNumber, ExpirationDate = expDate, Name = cardName, User = userToAdd }; var cardToAdd = this.mapper.Map <BankCardModel, BankCard>(c); userToAdd.BankCards.Add(cardToAdd); } this.users.Add(userToAdd); unitOfWork.SaveChanges(); return(true); } catch (System.Exception) { return(false); } }
public void AddProducts(ICollection <Product> products) { Guard.WhenArgument(products, "products").IsNull().Throw(); this.products.Add(products); unitOfWork.SaveChanges(); }
public IRepositoryAsync <SongEntity, Guid> RepositoryAsync() { _context.SaveChanges(); return(_context.RepositoryAsync <SongEntity, Guid>()); }