}//getListOfExchangesByCoupon public BaseViewModel createNewUser(SaveUserCommand command) { // Creates a new user instance and saves to DB (from registration page) BaseViewModel vmFinal = new BaseViewModel(); Entities.dbo.Users newUser = null; Entities.dbo.LicTransactions trans = null; Entities.dbo.Userlicenses userLic = null; if (command.User.Licence.Licensetype == 3) { if (command.Cupon != _Cupon) { // Invalid coupon vmFinal.Messages.Add(new Cherries.Models.App.Message { LogLevel = Cherries.Models.App.LogLevel.Error, Text = "Invalid coupon code" }); return(vmFinal); } } // Save user to DB if (validator.ValidatePassword(command.Password, vmFinal) && !validator.UserExists(command.User.Username, vmFinal) && validator.ValidatePayment(command.SumInServer, command.User.Licence.Transaction.dSum, vmFinal)) { // verifies user doesn't already exist + parameters inserted are legal repository.ExecuteTransaction(session => { if (command.User.Currency == null) { command.User.Currency = new Cherries.Models.Lookup.Currency { CurrencyId = "9001" } } ; newUser = AutoMapper.Mapper.Map <Entities.dbo.Users>(command.User); userLic = newUser.Userlicenses[0]; newUser.Userlicenses = null; SetPassword(newUser, command.Password, false); session.Save(newUser); trans = userLic.Transaction; session.Save(trans); userLic.User = newUser; userLic.Licensetypes = new Entities.Lookup.Licensetypes { Idlicensetype = command.User.Licence.Licensetype }; userLic.Transaction = trans; if (userLic.isTrial) { userLic.dtExpirationDate = DateTime.Today.AddDays(90); } else { userLic.dtExpirationDate = DateTime.Today.AddMonths(userLic.tb_LicServices.Imonths); } userLic.dtActivationDate = DateTime.Today; userLic.dtPurchaseDate = DateTime.Today; session.SaveOrUpdate(userLic); userLic.Licenseexchanges = new List <Entities.Lookup.Licenseexchanges>(); AddExchanges(userLic, command.User.Licence.Stocks.ToList()); session.SaveOrUpdate(userLic); }); } return(vmFinal); }//createNewUser
public BaseViewModel CreateUser(SaveUserCommand command) { BaseViewModel vm = new BaseViewModel(); Entities.dbo.Users newUser = null; Entities.dbo.LicTransactions trans = null; Entities.dbo.Userlicenses userLic = null; if (command.User.Licence.Licensetype == 3) { if ((command.Cupon != _Cupon) && (command.Cupon != _CuponIsrael)) { vm.Messages.Add(new Cherries.Models.App.Message { LogLevel = Cherries.Models.App.LogLevel.Error, Text = "Invalid coupon code" }); return(vm); } } if (validator.ValidatePassword(command.Password, vm) && !validator.UserExists(command.User.Username, vm) && validator.ValidatePayment(command.SumInServer, command.User.Licence.Transaction.dSum, vm)) { repository.ExecuteTransaction(session => { var user = session.Query <Entities.dbo.Users>().Where(x => x.Username == command.User.Username).FirstOrDefault(); if (command.User.Currency == null) { command.User.Currency = new Cherries.Models.Lookup.Currency { CurrencyId = "9001" } } ; newUser = AutoMapper.Mapper.Map <Entities.dbo.Users>(command.User); userLic = newUser.Userlicenses[0]; newUser.Userlicenses = null; SetPassword(newUser, command.Password, false); session.Save(newUser); trans = userLic.Transaction; session.Save(trans); userLic.User = newUser; userLic.Licensetypes = new Entities.Lookup.Licensetypes { Idlicensetype = command.User.Licence.Licensetype }; userLic.Transaction = trans; if (userLic.isTrial) { userLic.dtExpirationDate = DateTime.Today.AddDays(90); } else { userLic.dtExpirationDate = DateTime.Today.AddMonths(userLic.tb_LicServices.Imonths); } userLic.dtActivationDate = DateTime.Today; userLic.dtPurchaseDate = DateTime.Today; session.SaveOrUpdate(userLic); userLic.Licenseexchanges = new List <Entities.Lookup.Licenseexchanges>(); List <Cherries.Models.Lookup.StockMarket> finalExchanges = getListOfExchangesByCoupon(command.User.Licence.Stocks.ToList(), command); AddExchanges(userLic, finalExchanges); //AddExchanges(userLic, command.User.Licence.Stocks.ToList()); session.SaveOrUpdate(userLic); }); } return(vm); }