public Task <User> FindByNameAsync(string userName) { var user = _service.GetUserByName(userName); return(Task.FromResult <User>(user)); }
public ActionResult AddToOrder(string products) //посмотреть если методы добававления в заказ { int userId = 0; using (var user = new AuthenticationServiceClient()) { userId = user.GetUserByName(User.Identity.Name).Id; } using (var client = new OrderServiceClient()) { //Получаем все заказы var lastId = 0; if (client.GetOrders().LastOrDefault() == null) { lastId = 1; } else { lastId = client.GetOrders().Max(id => id.Id) + 1; } //Сериализация строки в класс List <CardListDetailsView> resultSerialProducts = System.Web.Helpers.Json.Decode <List <CardListDetailsView> >(products); //Создание заказа OrderService.OrderDataContract newOrder = new OrderService.OrderDataContract { //пойти в базуб получить id Id = lastId, User = User.Identity.Name, OrderDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second), OrderPrice = ((Func <decimal>)(() => { decimal price = 0; foreach (var prod in resultSerialProducts) { var tmp = prod.Price * prod.Count; price += tmp; } return(price); }))() }; //Добавление в бд новый заказ client.AddOrder(newOrder); //заполнение нового заказа List <OrderDetailsDataContract> orderDetails = new List <OrderDetailsDataContract>(); foreach (var item in resultSerialProducts) { orderDetails.Add(new OrderDetailsDataContract { Id = item.Id, Product = item.NameProduct, OrderId = newOrder.Id, Quantity = item.Count, TotalPrice = item.Price }); } //добавление в бд деталей заказа //client.AddOrderDetails(orderDetails); client.AddOrderDetails(orderDetails.ToArray()); }; return(RedirectToAction("Catalog", "Home")); }