public IEnumerable <Entities.Order> GetList(short status, DateTime fromCreatedDate, DateTime toCreatedDate) { string storeName = "admin_order_getlist_statistic_V1"; var lisOrders = new List <Entities.Order>(); try { using (var db = new PostgresSQL(ConnectionEntity.DBPosition.Master)) { using (var command = db.CreateCommand(storeName, true)) { command.Parameters.Add(NpgsqlParameter("@_status", status)); command.Parameters.Add(NpgsqlParameter("@_fromcreateddate", fromCreatedDate)); command.Parameters.Add(NpgsqlParameter("@_tocreateddate", toCreatedDate)); using (var reader = command.ExecuteReader()) { if (reader.HasRows) { while (reader.Read()) { var obj = new Entities.Order(); EntityBase.SetObjectValue(reader, ref obj); lisOrders.Add(obj); } } } } } } catch (Exception ex) { throw new Exception(string.Format("{0} => {1}", storeName, ex.ToString())); } return(lisOrders); }
/// <summary> /// The get by delivery order identifier /// Author: ThanhDT /// Created date: 8/11/2020 12:21 AM /// </summary> /// <param name="deliveryOrderId">The delivery order identifier.</param> /// <returns></returns> /// <exception cref="System.Exception"></exception> public Entities.Order GetByDeliveryOrderId(string deliveryOrderId) { string storeName = "admin_order_getbydeliveryorderid"; Entities.Order result; try { using (var db = new PostgresSQL(ConnectionEntity.DBPosition.Master)) { using (var command = db.CreateCommand(storeName, true)) { command.Parameters.Add(NpgsqlParameter("@_delivery_order_id", deliveryOrderId, NpgsqlDbType.Varchar)); using (var reader = command.ExecuteReader()) { if (reader.HasRows) { result = new Entities.Order(); reader.Read(); EntityBase.SetObjectValue(reader, ref result); } else { result = null; } } } } } catch (Exception ex) { throw new Exception(string.Format("{0} => {1}", storeName, ex.ToString())); } return(result); }
void cboExtraType_SelectedIndexChanged(object sender, EventArgs e) { eExtraType extraType = (eExtraType)Enum.Parse(typeof(eExtraType), cboExtraType.SelectedValue.Replace(" ", "")); if (this.OrderID > 0) { Facade.IOrder facOrder = new Facade.Order(); Entities.Order order = facOrder.GetForOrderID(this.OrderID); IEnumerable <Repositories.DTOs.RateSurcharge> surcharges = null; try { Repositories.DTOs.RateInformation rateInfo = facOrder.GetRate(order, true, out surcharges); } catch (ApplicationException) { // Swallow application exceptions as get rate can fall over if a rate cannot be // found for a given postcode. If this happens then we don't really care. } if (surcharges != null) { var rs = (from s in surcharges where s.ExtraTypeID == (int)extraType select s).FirstOrDefault(); if (rs != null) { rntAmount.Value = (double?)rs.ForeignRate; } } } }
public void SubmitOrder(Entities.Order pOrder) { using (TransactionScope lScope = new TransactionScope()) using (VideoStoreEntityModelContainer lContainer = new VideoStoreEntityModelContainer()) { try { // Only Request the transfer, delivery will be placed after the trasfer succeed pOrder.OrderNumber = Guid.NewGuid(); // update the stock levels for this order before the fund is transferred, //because the items should be reserved for this user // if there is anything wrong with the fund transfer, the stock levels will be added back pOrder.UpdateStockLevels(); TransferFundsFromCustomer(pOrder.OrderNumber, pOrder.Customer.BankAccountNumber, pOrder.Total ?? 0.0); Console.WriteLine("Fund transfer of order: " + pOrder.OrderNumber + " has been requested to the bank"); lContainer.Orders.ApplyChanges(pOrder); lContainer.SaveChanges(); } catch (Exception lException) { SendTransferErrorEmail(pOrder.OrderNumber, lException.Message); Console.WriteLine("Something wrong happened. The fund transferr request were not able to be placed."); Console.WriteLine("Exception Message:" + lException.Message); throw; } finally { lScope.Complete(); } } }
public bool CreateNewOrder(Entities.Order order) { return(GetConnection(con => { int rowAffected; using (var command = CreateCommand <SqlCommand>(con, CreateNewOrderQuery)) { command.Parameters.AddWithValue("@customerId", order.CustomerId); command.Parameters.AddWithValue("@employeeId", order.EmployeeId); command.Parameters.AddWithValue("@orderDate", order.OrderDate); command.Parameters.AddWithValue("@requiredDate", order.RequiredDate); command.Parameters.AddWithValue("@shippedDate", order.ShippedDate); command.Parameters.AddWithValue("@shipVia", order.ShipVia); command.Parameters.AddWithValue("@freight", order.Freight); command.Parameters.AddWithValue("@shipName", order.ShipName); command.Parameters.AddWithValue("@shipAddress", order.ShipAddress); command.Parameters.AddWithValue("@shipCity", order.ShipCity); command.Parameters.AddWithValue("@shipRegion", order.ShipRegion); command.Parameters.AddWithValue("@shipPostalCode", order.ShipPostalCode); command.Parameters.AddWithValue("@shipCountry", order.ShipCountry); rowAffected = command.ExecuteNonQuery(); } return rowAffected == 1; })); }
public IEnumerable <Entities.Order> GetListToDelivery(short status, int limit) { string storeName = "service_order_get_list_to_delivery"; var lisOrders = new List <Entities.Order>(); try { using (var db = new PostgresSQL(ConnectionEntity.DBPosition.Master)) { using (var command = db.CreateCommand(storeName, true)) { command.Parameters.Add(NpgsqlParameter("@_status", status)); command.Parameters.Add(NpgsqlParameter("@_limit", limit)); using (var reader = command.ExecuteReader()) { if (reader.HasRows) { while (reader.Read()) { var obj = new Entities.Order(); EntityBase.SetObjectValue(reader, ref obj); lisOrders.Add(obj); } } } } } } catch (Exception ex) { throw new Exception(string.Format("{0} => {1}", storeName, ex.ToString())); } return(lisOrders); }
public async Task <IActionResult> SubmitRequest([FromBody] OrderForCreation order) { if (order?.Equipments == null || !order.Equipments.Any(e => e.Days > 0)) { return(BadRequest()); } var rentals = _rentalService.CreateRentals(order); var newOrder = new Entities.Order() { Rentals = rentals.ToList() }; await _ordersRepository.AddOrder(newOrder); if (!await _ordersRepository.SaveAsync()) { var err = new Exception("Adding new order failed on save."); Log.Error(err, err.Message); throw err; } return(CreatedAtRoute("GetOrder", new { orderId = newOrder.OrderId }, newOrder.OrderId)); }
public Domain.Models.Order Update(Domain.Models.Order updated) { Entities.Order dbOrder = mapper.Map(updated, context, true); context.SaveChanges(); //context.ChangeTracker.Clear(); return(mapper.Map(dbOrder)); }
//----------------------------------------------------------------------------------------------------------- private void ChangeExistingInstruction(Entities.Instruction instruction, Entities.Job run, List <int> orderIds) { Facade.IInstruction facInstruction = new Facade.Instruction(); // no need to create a new instruction. Entities.FacadeResult retVal = new Entities.FacadeResult(); Orchestrator.Facade.IOrder facOrder = new Orchestrator.Facade.Order(); Facade.Job facJob = new Facade.Job(); Entities.CollectDropCollection collectDrops = new Orchestrator.Entities.CollectDropCollection(); // Update the Order and the relevant instructions foreach (int ordId in orderIds) { DataSet dsOrders = facOrder.GetLegsForOrder(ordId); // Get the last job id from the dataset int jobId = -1; if (dsOrders.Tables[0].Rows.Count > 0) { jobId = Convert.ToInt32(dsOrders.Tables[0].Rows[dsOrders.Tables[0].Rows.Count - 1]["JobID"].ToString()); } Entities.Order currentOrder = facOrder.GetForOrderID(ordId); if (instruction.CollectDrops.GetForOrderID(currentOrder.OrderID) != null) { facInstruction.UpdatePointID(instruction.InstructionID, this.cboNewDeliveryPoint.PointID, this.Page.User.Identity.Name); instruction.PointID = this.cboNewDeliveryPoint.PointID; this.UpdateOrder(currentOrder); instruction.BookedDateTime = currentOrder.DeliveryDateTime; instruction.PlannedArrivalDateTime = currentOrder.DeliveryDateTime; instruction.PlannedDepartureDateTime = currentOrder.DeliveryDateTime; } } }
public IEnumerable<Entities.Order> GetAll() { var result = new List<Entities.Order>(); using (var connection = new SqlConnection(ConnectionString)) { var command = new SqlCommand("SELECT OrderID,OrderDate,ShippedDate from Orders"); connection.Open(); using (var reader = command.ExecuteReader()) { while (reader.Read()) { var order = new Entities.Order ( reader.GetInt32(0), reader.GetDateTime(1), reader.GetDateTime(2) ); order.SetStatus(); result.Add(order); } } return result; } }
public void SubmitOrder(Entities.Order pOrder) { using (TransactionScope lScope = new TransactionScope()) { LoadMediaStocks(pOrder); MarkAppropriateUnchangedAssociations(pOrder); using (VideoStoreEntityModelContainer lContainer = new VideoStoreEntityModelContainer()) { try { pOrder.OrderNumber = Guid.NewGuid(); TransferFundsFromCustomer(UserProvider.ReadUserById(pOrder.Customer.Id).BankAccountNumber, pOrder.Total ?? 0.0); pOrder.UpdateStockLevels(); PlaceDeliveryForOrder(pOrder); lContainer.Orders.ApplyChanges(pOrder); lContainer.SaveChanges(); lScope.Complete(); } catch (Exception lException) { SendOrderErrorMessage(pOrder, lException); throw; } } } SendOrderPlacedConfirmation(pOrder); }
private void RemoveOrdersFromOriginalGroup() { IDictionary <int, List <int> > orderGroupIds = new Dictionary <int, List <int> >(); Facade.IOrder facOrder = new Facade.Order(); Facade.IOrderGroup facOrderGroup = new Facade.Order(); if (Orders.Count > 0) { foreach (int OrderId in Orders) { Entities.Order order = facOrder.GetForOrderID(OrderId); KeyValuePair <int, List <int> > item = orderGroupIds.FirstOrDefault(kv => kv.Key == order.OrderGroupID); if (item.Value != null && item.Value.Count > 0) { item.Value.Add(OrderId); } else { orderGroupIds.Add(order.OrderGroupID, new List <int>() { OrderId }); } } } foreach (KeyValuePair <int, List <int> > pair in orderGroupIds) { facOrderGroup.RemoveOrdersFromGroup(pair.Key, pair.Value, ((CustomPrincipal)Page.User).UserName); } }
protected override async Task Handle(AddOrderCommand request, CancellationToken cancellationToken) { if (request.OrderItems != null) { Entities.Order order = new Entities.Order(); ICollection <OrderItem> orderItemList = GetOrderItems(request.OrderItems, order); Shop seller = _allMarktContext.Shops.Find(request.ShopId); Customer buyer = _allMarktContext.Customers.Find(request.CustomerId); if (seller != null && buyer != null) { order.Seller = seller; order.Buyer = buyer; order.DeliveryPhoneNumber = request.DeliveryPhoneNumber; order.DeliveryAddress = request.DeliveryAddress; order.TotalPrice = request.TotalPrice; order.TimeOfOrder = DateTime.Now; order.AdditionalNotes = request.AdditionalNotes; order.OrderStatus = Status.Registered; order.AWB = request.AWB; order.OrderItems = orderItemList; _allMarktContext.Orders.Add(order); _allMarktContext.OrderItems.AddRange(orderItemList); await _allMarktContext.SaveChangesAsync(cancellationToken); } } }
public async Task <Domain.Order.Models.Order> Handle(FindOrderByNumberQuery request, CancellationToken _) { Entities.Order order = await unitOfWork.GetRepository <Entities.Order>() .GetFirstOrDefaultAsync(predicate: _order => _order.Number == request.Number); return(mapper.Map <Entities.Order, Domain.Order.Models.Order>(order)); }
/// <summary> /// The change to delivery /// Author: ThanhDT /// Created date: 8/11/2020 5:06 PM /// </summary> /// <param name="order">The order.</param> /// <returns></returns> /// <exception cref="System.Exception"></exception> public int ChangeToDelivery(Entities.Order order) { string storeName = "admin_order_change_to_delivery"; try { using (var db = new PostgresSQL(ConnectionEntity.DBPosition.Master)) { using (var command = db.CreateCommand(storeName, true)) { command.Parameters.Add(NpgsqlParameter("@_order_id", order.order_id)); //command.Parameters.Add(NpgsqlParameter("@_status", order.status)); command.Parameters.Add(NpgsqlParameter("@_delivery_status", order.delivery_status)); command.Parameters.Add(NpgsqlParameter("@_delivery_order_id", order.delivery_order_id, NpgsqlDbType.Varchar)); command.Parameters.Add(NpgsqlParameter("@_delivery_price", order.delivery_price)); command.Parameters.Add(NpgsqlParameter("@_delivery_estimate_time", order.delivery_estimate_time)); command.Parameters.Add(NpgsqlParameter("@_reason_note", order.reason_note, NpgsqlDbType.Varchar)); return((int)command.ExecuteScalar()); } } } catch (Exception ex) { throw new Exception(string.Format("{0} => {1}", storeName, ex.ToString())); } }
private bool CanBeRemovedFromDrop(Entities.Instruction dropInstruction, Entities.Order order, out string message) { var messageFragments = new List <string>(); // This order can only be removed from this delivery and placed on a trunk if: // * This would not result in the breaking of the chain - to test this the order's collection run delivery point must match the delivery run collection point. // * No refusals have been logged against this instruction - it is possible to remove the call-in but keep the refusal. if (order.CollectionRunDeliveryPointID != order.DeliveryRunCollectionPointID) { messageFragments.Add("The Order's Collection Point does not match the Collection Point on the Run."); } var facGoodsRefusal = new Facade.GoodsRefusal(); var dsGoodsRefusal = facGoodsRefusal.GetRefusalsForInstructionIdAndOrderId(dropInstruction.InstructionID, order.OrderID); if (dsGoodsRefusal.Tables[0].Rows.Count > 0) { messageFragments.Add("Refusals Logged"); } if (messageFragments.Count > 0) { message = String.Format("This Order cannot be Converted - {0}", String.Join(", ", messageFragments.ToArray())); grdOrdersOnDrop.ItemStyle.BackColor = System.Drawing.Color.FromName("FireBrick"); grdOrdersOnDrop.ItemStyle.ForeColor = System.Drawing.Color.White; } else { message = String.Empty; } errorMessage = message; return(messageFragments.Count == 0); }
protected void Page_Load(object sender, System.EventArgs e) { int orderID = Convert.ToInt32(Request.QueryString["orderID"]); Entities.Order order = null; if (orderID > 0) { string cacheName = "_orderNotes" + orderID.ToString(); if (Cache[cacheName] == null) { Facade.IOrder facOrder = new Facade.Order(); order = facOrder.GetForOrderID(orderID); if (order != null) { Cache.Add(cacheName, order, null, System.Web.Caching.Cache.NoAbsoluteExpiration, new TimeSpan(0, 20, 0), System.Web.Caching.CacheItemPriority.Normal, null); } } else { order = (Entities.Order)Cache[cacheName]; } } lblNotes.Text = order.Notes; }
public bool create(Entities.Order order, string userId) { try { using (context) { DL.Order newOrder = new DL.Order(); newOrder.UserId = userId; newOrder.Created = DateTime.Now; AspNetUser user = context.AspNetUsers.Where(u => u.Id == userId).FirstOrDefault(); newOrder.AspNetUser = user; List <OrderProduct> orderProducts = new List <OrderProduct>(); foreach (var item in order.items) { orderProducts.Add(new OrderProduct() { Product = context.Products.Where(p => p.Id == item.Item.Id).FirstOrDefault(), Quantity = item.Quantity }); } newOrder.OrderProducts = orderProducts; context.Orders.Add(newOrder); context.SaveChanges(); return(true); } } catch (System.Exception ex) { throw ex; } }
public void SubmitOrder(Entities.Order pOrder) { using (TransactionScope lScope = new TransactionScope()) { LoadMediaStocks(pOrder); MarkAppropriateUnchangedAssociations(pOrder); using (VideoStoreEntityModelContainer lContainer = new VideoStoreEntityModelContainer()) { try { pOrder.OrderNumber = Guid.NewGuid(); if (pOrder.CheckStockLevels()) { pOrder.UpdateStockLevels(); TransferFundsFromCustomer(UserProvider.ReadUserById(pOrder.Customer.Id).BankAccountNumber, pOrder.Total ?? 0.0, pOrder.OrderNumber.ToString()); } else { Console.WriteLine("Insufficient stock"); throw new Exception("Insufficient stock!"); } lContainer.Orders.ApplyChanges(pOrder); lContainer.SaveChanges(); lScope.Complete(); } catch (Exception lException) { Console.WriteLine("Error occured while upload stocks: " + lException.Message); throw; } } } }
public void Add(Entities.Order order) { using (var context = new ApplicationDbContext()) { context.Order.Add(order); context.SaveChanges(); } }
public PalletDelivery(Entities.Order palletOrder, eInstructionType palletAction, decimal charge, string destination, string pallettype) { PalletOrder = palletOrder; PalletAction = palletAction; Charge = charge; Destination = destination; PalletType = pallettype; }
public void Edit(Entities.Order order) { using (var context = new ApplicationDbContext()) { context.Entry(order).State = EntityState.Modified; context.SaveChanges(); } }
public void AddEditOrder(OrderDTO order, IList <RecipeDTO> recipesOfOrder) { using (var session = Hibernate.SessionFactory.OpenSession()) { Entities.Order o = null; var entityOfOrder = session.QueryOver(() => o) .Where(() => o.Id == order.Id) .SingleOrDefault(); if (entityOfOrder == null) { entityOfOrder = new Entities.Order(); } entityOfOrder.Comments = order.Comments; entityOfOrder.Date = order.Date; entityOfOrder.ItemCount = order.ItemCount; entityOfOrder.Name = order.Name; entityOfOrder.OrderNo = order.OrderNo; session.Clear(); session.SaveOrUpdate(entityOfOrder); session.Flush(); Recipe rec = null; o = null; var recipesForDeletion = session.QueryOver(() => rec) .JoinAlias(() => rec.Order, () => o) .Where(() => o.Id == order.Id) .List(); foreach (var r in recipesForDeletion) { session.Delete(r); session.Flush(); } foreach (var r in recipesOfOrder) { Measure m = null; Product p = null; var entityOfRecipe = new Recipe { Measure = session.QueryOver(() => m).Where(() => m.Id == r.MeasureId).SingleOrDefault(), Product = session.QueryOver(() => p).Where(() => p.Id == r.ProductId).SingleOrDefault(), MeasureCount = r.MeasureCount, Order = entityOfOrder }; session.Clear(); session.SaveOrUpdate(entityOfRecipe); session.Flush(); } } }
public OrderFullViewModel(Entities.Order order, Entities.District district, Entities.Ward ward, List <OrderDetailViewModel> lstOrderDetail) { OrderId = order.order_id; Code = order.code; CustomerName = order.customer_name; CityCode = order.city_code; DistrictId = order.district_id; if (district != null) { DistrictName = district.district_name; } WardId = order.ward_id; if (ward != null) { WardName = ward.ward_name; } DeliveryAddress = order.delivery_address; CustomerPhone = order.customer_phone; CustomerNote = order.customer_note; OrderType = order.order_type; OrderTypeName = Utils.GetEnumDescription((OrderTypeEnum)order.order_type); SourceType = order.source_type; SourceTypeName = Utils.GetEnumDescription((SourceTypeEnum)order.source_type); RequestType = order.request_type; RequestTypeName = Utils.GetEnumDescription((RequestTypeEnum)order.request_type); OrderPrice = order.price; OrderOriginPrice = order.origin_price; OrderPriceStr = StringUtils.ConvertNumberToCurrency(OrderPrice); OrderOriginPriceStr = StringUtils.ConvertNumberToCurrency(OrderOriginPrice); DeliveryStatusStr = Utils.GetEnumDescription((DeliveryStatus)(order.delivery_status)); CreatedBy = order.created_by; ModifiedBy = order.modified_by; ReasonNote = order.reason_note; Status = order.status; StatusStr = Utils.GetEnumDescription((OrderStatusEnum)(order.status)); ShipFee = order.ship_fee; ShipFeeStr = StringUtils.ConvertNumberToCurrency(ShipFee); CreatedDateStr = order.created_date.ToString("dd/MM/yyyy HH:mm:ss"); ModifiedDateStr = order.modified_date.ToString("dd/MM/yyyy HH:mm:ss"); CashierReceive = order.cashier_receive; CashierRefund = order.cashier_refund; //if (lstOrderDetail != null && lstOrderDetail.Count > 0) // this.lstOrderDetailViewModel = lstOrderDetail; if (order.delivery_date != DateTime.MinValue && order.delivery_date != null) { DeliverDate = order.delivery_date.Value; DeliveryDateStr = order.delivery_date.Value.ToString("dd/MM/yyyy HH:mm:ss"); } else { DeliveryDateStr = "Giao ngay"; } this.ListSourceType = EnumHelper.Instance.ConvertEnumToList <SourceTypeEnum>().ToList(); this.ListOrderType = EnumHelper.Instance.ConvertEnumToList <OrderTypeEnum>().ToList(); this.Discount = DVG.WIS.Utilities.AppSettings.Instance.GetString("DiscountValuePercent").ToInt() / 100 * this.OrderOriginPrice; this.DiscountStr = StringUtils.ConvertNumberToCurrency(this.Discount); }
public void Add(Entities.Order order) { using (var context = new OrderContext(_options)) { context.Orders.Add(order); context.SaveChanges(); } }
private Entities.Order GeneratePalletOrder(int palletTypeId, int noPallets, eInstructionType selectedPalletAction, ref string destination) { destination = string.Empty; int identityId = 0; bool deliveryIsAnytime = false; DateTime deliveryFromDateTime = new DateTime(); DateTime deliveryDateTime = new DateTime(); if (selectedPalletAction == eInstructionType.DeHirePallets) { identityId = int.Parse(rcbDeHireOrganisation.SelectedValue); } else { identityId = Orchestrator.Globals.Configuration.IdentityId; } deliveryFromDateTime = new DateTime(dteDeliveryFromDate.SelectedDate.Value.Year, dteDeliveryFromDate.SelectedDate.Value.Month, dteDeliveryFromDate.SelectedDate.Value.Day, dteDeliveryFromTime.SelectedDate.Value.Hour, dteDeliveryFromTime.SelectedDate.Value.Minute, 0); deliveryDateTime = new DateTime(dteDeliveryByDate.SelectedDate.Value.Year, dteDeliveryByDate.SelectedDate.Value.Month, dteDeliveryByDate.SelectedDate.Value.Day, dteDeliveryByTime.SelectedDate.Value.Hour, dteDeliveryByTime.SelectedDate.Value.Minute, 0); deliveryIsAnytime = rdDeliveryIsAnytime.Checked; Entities.Order palletOrder = new Entities.Order(); // Setting default values for the Order. palletOrder.Cases = 0; palletOrder.Weight = 0; palletOrder.GoodsTypeID = 1; // This REALLY needs to be Pallets ( hint hint system definition ). palletOrder.PalletSpaceID = (int)ePalletSize.Normal; palletOrder.CustomerOrderNumber = "palletHandling"; palletOrder.DeliveryOrderNumber = "palletHandling"; palletOrder.OrderStatus = eOrderStatus.Approved; palletOrder.OrderType = eOrderType.PalletHandling; palletOrder.OrderInstructionID = 3; // Find out what this is? palletOrder.CustomerIdentityID = identityId; palletOrder.PalletTypeID = palletTypeId; palletOrder.NoPallets = noPallets; palletOrder.PalletSpaces = palletOrder.NoPallets; palletOrder.PlannedForCollection = palletOrder.PlannedForDelivery = true; palletOrder.CollectionPointID = palletOrder.DeliveryPointID = ucDeliveryPoint.SelectedPoint.PointId; destination = ucDeliveryPoint.SelectedPoint.Description; palletOrder.ForeignRate = palletOrder.Rate = rntPalletDeliveryCharge.Value.HasValue ? (decimal)rntPalletDeliveryCharge.Value : 0m; palletOrder.CollectionDateTime = palletOrder.DeliveryFromDateTime = deliveryFromDateTime; palletOrder.CollectionByDateTime = palletOrder.DeliveryDateTime = deliveryDateTime; palletOrder.CollectionIsAnytime = palletOrder.DeliveryIsAnytime = deliveryIsAnytime; palletOrder.FuelSurchargePercentage = 0m; palletOrder.FuelSurchargeAmount = palletOrder.FuelSurchargeForeignAmount = 0m; return(palletOrder); }
private void OnOrder(object o, Message <string, Order.Api.Application.Events.OrderState> e) { using (var orderDbContext = new OrderDbContext()) { var unitOfWork = new UnitOfWork <OrderDbContext>(orderDbContext); var orderRepository = unitOfWork.GetRepository <Entities.Order>(); var order = (orderRepository.FirstOrDefault(x => x.OrderId == e.Value.id).Result); if (order == null) { var newOrder = new Entities.Order() { CustomerId = e.Value.customerId, Date = e.Value.date, OrderId = e.Value.id, Total = e.Value.total, Products = e.Value.products.Select(x => new Entities.OrderProduct() { ProductId = x.id, Quantity = x.Quantity }).ToList() }; orderRepository.Add(newOrder); } else { if (e.Value.status.Equals("WaitingForReservation")) { order.Status = Entities.Order.OrderStatus.WaitingForReservation; } else if (e.Value.status.Equals("WaitingForPayment")) { order.Status = Entities.Order.OrderStatus.WaitingForPayment; } else if (e.Value.status.Equals("Failed")) { order.Status = Entities.Order.OrderStatus.Failed; } else if (e.Value.status.Equals("Success")) { order.Status = Entities.Order.OrderStatus.Success; } orderRepository.Update(order); } var result = unitOfWork.SaveChanges().Result; if (!result.IsSuccessfull()) { throw new Exception(); } } }
public Models.Order OrderEntityToModel(Entities.Order order) => new MapperConfiguration(cfg => cfg.CreateMap <Entities.Order, Models.Order>() .ForMember(o => o.OrderInfo, opt => opt.MapFrom(src => OrderInfoEntityToModel(src.OrderInfo))) .ForMember(o => o.OrderItems, opt => opt.MapFrom(src => OrderItemEntitiesToModels(src.OrderItems))) .ForMember(o => o.OrdUser, opt => opt.MapFrom(src => OrdUserEntityOrdUserForOrderToModel(src.OrdUser)))) .CreateMapper() .Map <Models.Order>(order);
public void Remove(Domain.Models.Order t) { Entities.Order dbOrder = mapper.Map(t, context); Entities.Order order = context.Orders.ToList().Find(o => o.GetHashCode() == dbOrder.GetHashCode()); if (order is not null) { context.Remove(order); context.SaveChanges(); } }
public void Remove(int id) { Entities.Order order = context.Orders.FirstOrDefault(o => o.ID == id); if (order is not null) { context.Remove(order); context.SaveChanges(); //context.ChangeTracker.Clear(); } }
private async Task <Entities.Order> CreateOrderByUserId(int userId) { Entities.Order order = new Entities.Order() { ShopUserId = userId, IsCheckedOut = false, OrderLines = new List <OrderLine>() }; await _orderRepository.AddAsync(order); return(order); }
public Entities.Order GetOrder(long id) { Entities.Order found = null; List<Entities.Pizza> pizzas = null; List<Entities.Beverage> beverages = null; List<Entities.Dessert> desserts = null; double pizzaCost, beverageCost, dessertCost; try { var item = context.Orders.FirstOrDefault(order => order.Id == id); if (item != null) { pizzaCost = this.SliptSlicesToMeasureCost(item.Order_Pizzas.OrderBy(i => i.Slice).ToList()); pizzas = new List<Entities.Pizza>(); foreach (Order_Pizzas order_Pizzas in item.Order_Pizzas.OrderBy(i => i.Slice)) pizzas.Add(new Entities.Pizza() { Id = order_Pizzas.Id_Pizza, Flavor = order_Pizzas.Pizza.Flavor, Description = order_Pizzas.Pizza.Description, Price = order_Pizzas.Pizza.Price, Slice = order_Pizzas.Slice }); beverageCost = 0; beverages = new List<Entities.Beverage>(); foreach (Order_Beverages order_Beverages in item.Order_Beverages) { beverages.Add(new Entities.Beverage() { Id = order_Beverages.Beverage.Id, Name = order_Beverages.Beverage.Name, Price = order_Beverages.Beverage.Price }); beverageCost += order_Beverages.Beverage.Price; } dessertCost = 0; desserts = new List<Entities.Dessert>(); foreach (Order_Desserts order_Desserts in item.Order_Desserts) { desserts.Add(new Entities.Dessert() { Id = order_Desserts.Desserts.Id, Name = order_Desserts.Desserts.Name, Price = order_Desserts.Desserts.Price }); dessertCost += order_Desserts.Desserts.Price; } found = new Entities.Order() { Id = item.Id, Customer = item.Id, Created = item.Created, Delivered = item.Delivered, Pizzas = pizzas.ToArray(), Beverages = beverages.ToArray(), Desserts = desserts.ToArray(), PizzaCost = pizzaCost, BeverageCost = beverageCost, DessertCost = dessertCost }; } return found; } finally { found = null; pizzas = null; beverages = null; desserts = null; } }