private static void ChangeStatus(ContractDetailsDto contractDetails, string text) { using (var context = new PawnShopContext()) { var contract = context.Contracts.Find(contractDetails.Id); contract.Status = (Status)Enum.Parse(typeof(Status), text); if (text == "Saled") { CommandParser parser = new CommandParser(); var command = parser.ParseCommand(new[] { "CashBoxTransaction", "Deposit", contract.PropertyValue.ToString(), "Sold item" }); command.Execute(); } if (text == "Ended") { CommandParser parser = new CommandParser(); var command = parser.ParseCommand(new[] { "CashBoxTransaction", "Deposit", (contract.PropertyValue * contract.Interest).ToString(), "Ended item" }); command.Execute(); } context.SaveChanges(); } }
private void RegisterUser(string officeName, string username, string password, string confirmedPassword) { using (var context = new PawnShopContext()) { if (context.Users.Any(u => u.Credentials.Email == username)) { throw new ArgumentException($"User with that username already exists!"); } if (!password.Equals(confirmedPassword)) { throw new ArgumentException($"Passwords do not match!"); } if (LoginUser.User != null) { throw new ArgumentException($"Login users cannot register. Logout first!"); } var office = context.Offices.FirstOrDefault(o => o.Name == officeName); var user = new User() { Office = office, Credentials = new Credentials() { Email = username, Password = password } }; context.Users.Add(user); context.SaveChanges(); LoginUser.User = user; } }
private void CashBoxTransaction(OperationType operationType, decimal value, string details) { using (var context = new PawnShopContext()) { context.Users.Attach(LoginUser.User); if (operationType == OperationType.Deposit) { LoginUser.User.Office.CashBox.Balance += value; } else { LoginUser.User.Office.CashBox.Balance -= value; } var cashOperation = new CashOperation() { CashBox = LoginUser.User.Office.CashBox, Details = details, OperationType = operationType, Value = value }; context.CashOperations.Add(cashOperation); context.SaveChanges(); } }
private void AddNewContract(string property, decimal properyValue, decimal interest, DateTime endDate, string clientName) { using (var context = new PawnShopContext()) { var client = context.Clients.FirstOrDefault( c => string.Concat(c.FirstName, " ", c.MiddleName, " ", c.LastName) == clientName); var user = context.Users.FirstOrDefault(); var contract = new Contract() { PledgedProperty = property, PropertyValue = properyValue, Interest = interest, StartDate = DateTime.Today, EndDate = endDate, Employee = user, Client = client, Status = Status.New }; context.Contracts.Add(contract); context.SaveChanges(); } }
private void ExitCommand(object sender, RoutedEventArgs e) { using (var context = new PawnShopContext()) { var contractToDelete = context.Contracts.Where(c => c.Status == Status.Saled).ToList(); foreach (var contract in contractToDelete) { context.Contracts.Remove(contract); } context.SaveChanges(); } }
private static void AddNewClient(string address, string firstName, string middleName, string lastName, string personalId, string idCardNumber, string phonenumber, string town, string property, string propertyValue, string interest, string endDate) { using (var context = new PawnShopContext()) { var addressLiving = context.Addresses.FirstOrDefault(a => a.Text == address); var client = new Client() { FirstName = firstName, MiddleName = middleName, LastName = lastName, PersonalID = int.Parse(personalId), IDCardNumber = idCardNumber, PhoneNumber = phonenumber, RegistrationDate = DateTime.Now }; var townLiving = context.Towns.FirstOrDefault(t => t.Name == town); if (townLiving == null) { townLiving = new Town() { Name = town }; } if (addressLiving == null) { client.Address = new ClientAddress() { Text = address, Town = townLiving }; } else { client.Address = (ClientAddress)addressLiving; } var clientName = client.FirstName + " " + client.MiddleName + " " + client.LastName; context.Clients.Add(client); context.SaveChanges(); AddContract.AddNewContract(property, decimal.Parse(propertyValue), decimal.Parse(interest), DateTime.Parse(endDate), clientName); } }
private void CashBoxTransaction(OperationType operationType, decimal value, string details) { if (value <= 0) { throw new ArgumentException("Invalid value"); } using (var context = new PawnShopContext()) { context.Users.Attach(LoginUser.User); var cashOperation = new CashOperation() { CashBox = LoginUser.User.Office.CashBox, Details = details, OperationType = operationType, Value = value, DateTime = DateTime.Now, CashBoxValueBefore = LoginUser.User.Office.CashBox.Balance }; if (operationType == OperationType.Deposit) { LoginUser.User.Office.CashBox.Balance += value; } else { LoginUser.User.Office.CashBox.Balance -= value; } cashOperation.CashBoxValueAfter = LoginUser.User.Office.CashBox.Balance; context.CashOperations.Add(cashOperation); context.SaveChanges(); } }