private OrderItemAdded CreateEvent(Model.Order.Order state) { var evn = CreateEvent <OrderItemAdded>(state); evn.Description = Description; evn.Cost = Cost; return(evn); }
private void Validate(Model.Order.Order state) { if (state.CheckedOut) { throw new ArgumentException(nameof(state.CheckedOut)); } if (!state.Items.Any()) { throw new InvalidDataException(nameof(state.Items)); } }
private void Validate(Model.Order.Order state) { if (string.IsNullOrWhiteSpace(Description)) { throw new InvalidDataException(nameof(Description)); } if (state.CheckedOut) { throw new ArgumentException(nameof(state.CheckedOut)); } }
public OperationResult AddOrder(Model.Order.Order order) { var result = OperationResult.CreateWithSuccess(); using (var context = new StoreCoreContext()) { var client = context.inf_client.FirstOrDefault(f => f.id == order.ClientId && f.record_state != 1); var product = context.inf_product.FirstOrDefault(f => f.id == order.ProductId && f.record_state != 1); if (client == null) { return(OperationResult.CreateWithError("Client ID is invalid!")); } if (product == null) { return(OperationResult.CreateWithError("Product ID is invalid!")); } if (product.count < order.Count) { return(OperationResult.CreateWithError("Your order amount is not available!")); } if (order != null) { var dbOrder = context.inf_order.Create(); dbOrder.client_id = order.ClientId; dbOrder.product_id = order.ProductId; dbOrder.count = order.Count; dbOrder.amount = product.price; dbOrder.creation_date = DateTime.UtcNow; dbOrder.record_updated = DateTime.UtcNow; dbOrder.record_state = 0; context.inf_order.Add(dbOrder); context.SaveChanges(); product.count = product.count - order.Count; product.record_state = 2; product.record_updated = DateTime.UtcNow; context.SaveChanges(); } else { return(OperationResult.CreateWithError("Error")); } } return(result); }
public OrderPlacementViewModel() { MashroomCount = 0; PannerCount = 0; SevenUpCount = 0; Order = new Model.Order.Order(); AddCommand = new RelayCommand.RelayCommand( AddMethod); SubCommand = new RelayCommand.RelayCommand( SubMethod); CustomCommand = new RelayCommand.RelayCommand(Custom); AddOrderCommand = new RelayCommand.RelayCommand(AddCustomToOrder); Foods = new ObservableCollection <Model.Common.Food>(); PizzaSandwitchCustomOptions = new List <CustomizationOption>(); }
public void GivenAListOfBookingsWithTheFollowingInformationFor(string businessId, string roomType, string roomName, string guestFirstName, string guestLastName, string guestPostCode, string guestEmail, string guestPhone, Table table) { foreach(var row in table.Rows) { var bookingBusinessId = Convert.ToInt16(row[businessId]); var roomTypeId = roomTypeDao.GetRoomTypeIdByNameAndBusiness(row[roomType], bookingBusinessId); var room = roomDao.GetByName(row[roomName], bookingBusinessId); var ratePlanId = ratePlanDao.GetRatePlanByRoomTypeIdAndBusiness(roomTypeId, bookingBusinessId); var booking = new Booking { BusinessId = bookingBusinessId, StartDate = DateTime.Today.Date, EndDate = DateTime.Today.AddDays(3).Date, CheckinStatus = new EnumEntity{ Code = "N"}, BookingScenarioType = BookingScenarioTypeEnum.Prepaid, NumberOfAdults = 2, NumberOfChildren = 1, RateType = new EnumEntity { Code = RateType.BEST_AVAILABLE_RATE }, AmountPaid = 100, Cost = 0, Guest = new Guest { TitleId = 1, BusinessId = bookingBusinessId, Forename = row[guestFirstName], Surname = row[guestLastName], PostCode = row[guestPostCode], Email = row[guestEmail], AddressLine1 = "AddressLine 1", AddressLine2 = "AddressLine 2", AddressLine3 = "AddressLine 3", DefaultCultureCode = "en-GB", GuestPhones = new List<GuestPhone> { new GuestPhone { Number = row[guestPhone], PhoneTypeCode = PhoneTypeEnum.Contact1 } } }, RoomTypeId = roomTypeId, RoomId = room.Id, RatePlanId = ratePlanId, BookingStatus = new EnumEntity {Code = BookingStatusType.CONFIRMED} }; guestManager.Create(booking.Guest); Model.Order.Order order = new Model.Order.Order { OrderSourceCode = SourceType.Online.GetCode(), IntegrationType = IntegrationTypeEnum.RequestResponse, ChannelReference = "GHJDGSS", CustomerCurrencyCode = "GBP", Bookings = new List<Booking> { booking } }; orderManager.CreateOrder(bookingBusinessId, order); } }
public OrderCheckedOut Execute(Model.Order.Order state) { Validate(state); return(CreateEvent <OrderCheckedOut>(state)); }
/// <summary> /// Map the basic fields for the Order table to the Order model object /// </summary> /// <param name="record">The SqlDataReader with the executed query result</param> /// <param name="prefix">a prefix used to identify fields for the Order model in the resultset if required</param> /// <returns>An instance of Model.Order.Order</returns> private static Model.Order.Order MapRecord(IDataRecord record, string prefix = "") { var order = new Model.Order.Order { Id = DbHelper.ConvertValue<int>(record[prefix + Parameters.Id]), OrderSourceCode = DbHelper.ConvertValue<string>(record[prefix + Parameters.OrderSourceCode]), OrderSourceName = DbHelper.ConvertValue<string>(record[prefix + Parameters.OrderSourceName]), ChannelId = DbHelper.ConvertValueNull<int>(record[prefix + Parameters.ChannelId]), ChannelReference = DbHelper.ConvertValue<string>(record[prefix + Parameters.ChannelReference]), IntegrationType = DbHelper.ConvertEnumValue<IntegrationTypeEnum>(record[prefix + Parameters.IntegrationTypeCode]), AgentId = DbHelper.ConvertValueNull<int>(record[prefix + Parameters.AgentId]), OfflineSourceEnum = DbHelper.ConvertEnumValue<OfflineSourceEnum>(record[prefix + Parameters.OfflineSourceCode]), CustomerCultureCode = DbHelper.ConvertValue<string>(record[prefix + Parameters.CustomerCultureCode]), CustomerCurrencyCode = DbHelper.ConvertValue<string>(record[prefix + Parameters.CustomerCurrencyCode]), CurrencySymbol = DbHelper.ConvertValue<string>(record[prefix + Parameters.CurrencySymbol]), CustomerTimezoneId = DbHelper.ConvertValue<int>(record[prefix + Parameters.CustomerTimezoneId]), OrderDatetime = DbHelper.ConvertValueNull<DateTime>(record[prefix + Parameters.OrderDatetime]), TotalNetValue = DbHelper.ConvertValue<decimal>(record[prefix + Parameters.TotalNetValue]), TotalValue = DbHelper.ConvertValueNull<decimal>(record[prefix + Parameters.TotalValue]), AmountPaid = DbHelper.ConvertValue<decimal>(record[prefix + Parameters.AmountPaid]), AmountRefunded = DbHelper.ConvertValue<decimal>(record[prefix + Parameters.AmountRefunded]), LeadGuestId = DbHelper.ConvertValue<int>(record[prefix + Parameters.LeadGuestId]), LeadGuest = GuestMapper.MapDetailRecord(record, "Guest"), GroupReference = DbHelper.ConvertValue<string>(record[prefix + Parameters.GroupReference]), OrderReference = DbHelper.ConvertValue<string>(record[prefix + Parameters.OrderReference]), CCToken = DbHelper.ConvertValue<string>(record[prefix + Parameters.CCToken]), CCTokenSource = DbHelper.ConvertValue<string>(record[prefix + Parameters.CCTokenSource]), FirstBookingId = DbHelper.ConvertValue<int?>(record[prefix + Parameters.FirstBookingId]), FirstBookingRoomName = DbHelper.ConvertValue<string>(record[prefix + Parameters.FirstBookingRoomName]), FirstBookingGuestSurname = DbHelper.ConvertValue<string>(record[prefix + Parameters.FirstBookingGuestSurname]), Notes = DbHelper.ConvertValue<string>(record[prefix + Parameters.Notes]), IsIssue = DbHelper.ConvertValue<bool?>(record[prefix + Parameters.IsIssue]), ReasonForIssue = DbHelper.ConvertValue<string>(record[prefix + Parameters.ReasonForIssue]) }; if (order.ChannelId.HasValue) { order.Channel = new Channel { Id = order.ChannelId.Value, Name = DbHelper.ConvertValue<string>(record[prefix + Parameters.ChannelName]), ShortName = DbHelper.ConvertValue<string>(record[prefix + Parameters.ChannelShortName]), CommissionType = DbHelper.ConvertEnumValue<CommissionTypeEnum>(record[prefix + Parameters.ChannelCommissionType]) }; } if (order.OfflineSourceEnum == OfflineSourceEnum.Unknown) { order.OfflineSourceEnum = null; } return AuditFieldsHelper.MapRecord(order, record, prefix); }
public OperationResult UpdateOrder(Model.Order.Order order) { var result = OperationResult.CreateWithSuccess(); using (var context = new StoreCoreContext()) { var dbProduct = context.inf_product.FirstOrDefault(f => f.id == order.ProductId && f.record_state != 1); var dbOrder = context.inf_order.FirstOrDefault(f => f.id == order.Id && f.record_state != 1); if (dbProduct == null) { return(OperationResult.CreateWithError("Product ID is invalid!")); } if (dbProduct.count < order.Count) { return(OperationResult.CreateWithError("Your order amount is not available!")); } if (dbOrder != null) { var productId = dbOrder.product_id; var prodAmount = dbOrder.count; dbOrder.product_id = order.ProductId; dbOrder.count = order.Count; dbOrder.amount = dbProduct.price; dbOrder.record_updated = DateTime.UtcNow; dbOrder.record_state = 2; context.SaveChanges(); if (prodAmount < order.Count) { var res = order.Count - prodAmount; dbProduct.count = dbProduct.count - res; dbProduct.record_state = 2; dbProduct.record_updated = DateTime.UtcNow; context.SaveChanges(); } if (prodAmount > order.Count) { var res1 = prodAmount - order.Count; dbProduct.count = dbProduct.count + res1; dbProduct.record_state = 2; dbProduct.record_updated = DateTime.UtcNow; context.SaveChanges(); } if (dbOrder.product_id != productId) { var dbOldProduct = context.inf_product.FirstOrDefault(f => f.id == productId & f.record_state != 1); if (dbOldProduct != null) { dbOldProduct.count = dbOldProduct.count + prodAmount; dbOldProduct.record_state = 2; dbOldProduct.record_updated = DateTime.UtcNow; context.SaveChanges(); dbProduct.count = dbProduct.count - prodAmount; dbProduct.record_state = 2; dbProduct.record_updated = DateTime.UtcNow; context.SaveChanges(); } } } else { return(OperationResult.CreateWithError("Error")); } } return(result); }
public OrderItemAdded Execute(Model.Order.Order state) { Validate(state); return(CreateEvent(state)); }