public OrderAcceptInputModel LoadOrderAcceptInputModel(OrderAcceptInputModel model = null) { if (model is null) { model = new OrderAcceptInputModel(); } model.CompanyItems = this.companies.AllAsNoTracking() .Select(c => new KeyValuePair <string, string>(c.Id.ToString(), $"{c.Name} - {c.TaxNumber}")) .ToList(); model.LoadingBodyItems = this.loadingBodies.AllAsNoTracking() .Select(lb => new KeyValuePair <string, string>(lb.Id.ToString(), lb.Name)) .ToList(); model.CargoTypeItems = this.cargoTypes.AllAsNoTracking() .Select(ct => new KeyValuePair <string, string>(ct.Id.ToString(), ct.Name)) .ToList(); model.CurrencyItems = this.currencies.AllAsNoTracking() .Select(c => new KeyValuePair <string, string>(c.Id.ToString(), c.Name)) .ToList(); model.ActionTypeItems = this.actionTypes.AllAsNoTracking() .Select(at => new KeyValuePair <string, string>(at.Id.ToString(), at.Name)) .ToList(); TaxCountryNames res; model.TaxCountryItems = this.taxCountries.AllAsNoTracking() .Select(tc => new KeyValuePair <string, string>(tc.Id.ToString(), tc.Name)) .ToList() .Where(r => Enum.TryParse <TaxCountryNames>(r.Value, true, out res)); return(model); }
public async Task <IActionResult> Accept(OrderAcceptInputModel input) { if (!this.ModelState.IsValid) { foreach (var modelState in this.ModelState.Values) { foreach (var error in modelState.Errors) { this.notyfService.Error(this.localizer[error.ErrorMessage]); } } input = this.ordersService.LoadOrderAcceptInputModel(input); return(this.View(input)); } await this.ordersService.AcceptAsync(input, this.User); this.notyfService.Success(this.localizer["Order accepted."]); return(this.RedirectToAction("Accepted")); }
public async Task <string> AcceptAsync(OrderAcceptInputModel input, ClaimsPrincipal user) { var order = new Order { CreatorId = this.userManager.GetUserId(user), DueDaysFrom = input.DueDaysFrom, Status = this.orderStatuses.All().FirstOrDefault(s => s.Name == OrderStatusNames.Accepted.ToString()), OrderTos = new List <OrderTo>(), }; var orderFrom = new OrderFrom { CompanyId = input.CompanyFromId, ContactId = input.ContactFromId, TypeId = null, }; await this.orders.AddAsync(order); foreach (var orderToInput in input.OrderTos) { var orderTo = new OrderTo { PriceNetIn = orderToInput.PriceNetIn, CurrencyInId = orderToInput.CurrencyInId, PriceNetOut = orderToInput.PriceNetOut, CurrencyOutId = orderToInput.CurrencyOutId, TypeId = null, }; var cargo = new Cargo { TypeId = orderToInput.Cargo.TypeId, VehicleType = this.vehicleTypes.All().FirstOrDefault(vt => vt.Name == VehicleTypeNames.Truck.ToString()), LoadingBodyId = orderToInput.Cargo.LoadingBodyId, VehicleRequirements = orderToInput.Cargo.VehicleRequirements, Name = orderToInput.Cargo.Name, Lenght = orderToInput.Cargo.Lenght, Width = orderToInput.Cargo.Width, Height = orderToInput.Cargo.Height, WeightGross = orderToInput.Cargo.WeightGross, WeightNet = orderToInput.Cargo.WeightNet, Cubature = orderToInput.Cargo.Cubature, Quantity = orderToInput.Cargo.Quantity, Details = orderToInput.Cargo.Details, }; var documentation = this.mapper.Map <Documentation>(orderToInput.Documentation); documentation.RecievedDocumentation = new Documentation(); documentation.OrderToId = orderTo.Id; orderTo.AdminId = order.AdminId; cargo.AdminId = order.AdminId; orderTo.Cargo = cargo; documentation.AdminId = order.AdminId; documentation.RecievedDocumentation.AdminId = order.AdminId; orderTo.Documentation = documentation; var actions = orderToInput.OrderActions.OrderBy(a => a.TypeId); foreach (var actionIM in actions) { var action = this.mapper.Map <OrderAction>(actionIM); action.AdminId = order.AdminId; action.Address.AdminId = order.AdminId; orderTo.OrderActions.Add(action); } order.OrderTos.Add(orderTo); } orderFrom.AdminId = order.AdminId; order.OrderFrom = orderFrom; await this.orders.SaveChangesAsync(); return(order.Id); }