public async Task <IActionResult> Create() { OfferOrderVM vm = new OfferOrderVM(); // Initialize models, vars vm.Order.SharedInfo = new SharedInfo(); vm.Order.SharedInfo.ReceiveDate = DateTime.Now; vm.Order.SharedInfo.Currency = new Currency() { Name = "CZK", }; // TODO: Dat do PopulateModel nebo tak nejak string domainUser = User.GetLoggedInUserName(); string username = domainUser.Split('\\').LastOrDefault(); int userId = await _eveDbDochna.tUsers.Where(x => x.TxAccount == username).Select(x => x.Id).FirstOrDefaultAsync(); vEmployees vEmployee = await _eveDbDochna.vEmployees.Where(x => x.Id == userId).FirstOrDefaultAsync(); vm.Order.EveContactName = vEmployee.FormatedName; vm.Order.KeyAccountManager = vEmployee.FormatedName; await populateModelAsync(vm); await defaultEvePreselected(vm); return(View(vm)); }
private async Task defaultEvePreselected(dynamic vm) { // Fill default Division/Department/Username values of logged in user string domainAndUsername = User.GetLoggedInUserName(); string username = domainAndUsername.Split('\\').LastOrDefault(); int userId = await _eveDbDochna.tUsers.Where(x => x.TxAccount == username).Select(x => x.Id).FirstOrDefaultAsync(); vEmployees employee = await _eveDbDochna.vEmployees.Where(x => x.Id == userId).FirstOrDefaultAsync(); vm.Order.SharedInfo.EveCreatedUser = employee.FormatedName; vm.Order.SharedInfo.EveDepartment = employee.DepartName; vm.Order.SharedInfo.EveDivision = employee.EVE == 1 ? "EVE" : "EVAT"; }
public async Task <IActionResult> CreateFromContract(int?id) { Contract contract = await _db.Contracts .Include(x => x.SharedInfo.Currency) .FirstOrDefaultAsync(x => x.ContractsId == id); if (contract == null) { OfferOrderVM vmm = new OfferOrderVM(); await populateModelAsync(vmm); return(View(vmm)); } Order order = new Order(); order.ExchangeRate = decimal.Parse(getCurrencyStr(contract.SharedInfo.Currency.Name)); order.Contract = contract; order.ContractId = contract.ContractsId; order.SharedInfo = contract.SharedInfo; order.SharedInfoId = contract.SharedInfoId; // Fill nested models var shares = await _db.SharedInfo.ToListAsync(); var contacts = await _db.Contact.ToListAsync(); var currencies = await _db.Currency.ToListAsync(); var companies = await _db.Company.ToListAsync(); // TODO: Dat do PopulateModel nebo tak nejak string domainUser = User.GetLoggedInUserName(); string username = domainUser.Split('\\').LastOrDefault(); int userId = await _eveDbDochna.tUsers.Where(x => x.TxAccount == username).Select(x => x.Id).FirstOrDefaultAsync(); vEmployees vEmployee = await _eveDbDochna.vEmployees.Where(x => x.Id == userId).FirstOrDefaultAsync(); order.EveContactName = vEmployee.FormatedName; order.KeyAccountManager = vEmployee.FormatedName; OfferOrderVM vm = new OfferOrderVM() { // Contract = contract, Order = order }; await populateModelAsync(vm); return(View(vm)); }