internal IFacadeUpdateResult <ShipToData> SaveShipTo(ShipToDto dto) { ArgumentValidator.IsNotNull("dto", dto); FacadeUpdateResult <ShipToData> result = new FacadeUpdateResult <ShipToData>(); IShipToService service = UnitOfWork.GetService <IShipToService>(); ShipTo instance = RetrieveOrNew <ShipToData, ShipTo, IShipToService>(result.ValidationResult, dto.Id); if (result.IsSuccessful) { instance.Code = dto.Code; instance.CustomerId = dto.CustomerId; instance.ContactPerson = dto.ContactPerson; instance.ContactPhone = dto.ContactPhone; instance.AddressLine1 = dto.AddressLine1; instance.AddressLine2 = dto.AddressLine2; instance.Country = dto.Country; instance.CountryState = dto.CountryState; instance.City = dto.City; instance.ZipCode = dto.ZipCode; var saveQuery = service.Save(instance); result.AttachResult(instance.RetrieveData <ShipToData>()); result.Merge(saveQuery); } return(result); }
private void RetrieveData() { using (IUnitOfWork uow = UnitOfWorkFactory.Instance.Start(DataStoreResolver.CRMDataStoreKey)) { ShipToFacade facade = new ShipToFacade(uow); ShipToDto instance = facade.RetrieveOrNewShipTo(InstanceId, new ShipToConverter()); CurrentInstance = instance; ucIEdit.CurrentInstance = instance; } }
public List <OrderInfoDto> CreateOrdersFromCart(CartDto cart, ShipToDto shipTo) { ArgumentValidator.IsNotNull("cart", cart); ArgumentValidator.IsNotNull("shipTo", shipTo); List <OrderInfoDto> orders = new List <OrderInfoDto>(); // validate cart bool isValid = Validate(cart); if (isValid) { IEnumerable <object> supplierIds = cart.CartItems.Select(o => o.SupplierId).Distinct(); int orderNo = 0; foreach (object supplierId in supplierIds) { orderNo++; OrderInfoDto order = new OrderInfoDto(); order.OrderNumber = orderNo.ToString(); order.SupplierId = supplierId; order.ShipTo = shipTo; order.OrderItems = new List <OrderItemInfoDto>(); foreach (CartItemDto cartItem in cart.CartItems) { // filter by supplierId if (object.Equals(cartItem.SupplierId, supplierId)) { order.SupplierName = cartItem.SupplierName; OrderItemInfoDto orderItem = new OrderItemInfoDto(); order.OrderItems.Add(orderItem); orderItem.ProductId = cartItem.ProductId; orderItem.ProductName = cartItem.ProductName; orderItem.QtyOrdered = cartItem.QtyOrdered; orderItem.UnitPrice = cartItem.UnitPrice; orderItem.Amount = cartItem.Amount; } } order.QtyOrderedTotal = order.OrderItems.Sum(o => o.QtyOrdered); order.Amount = order.OrderItems.Sum(o => o.Amount); if (order.QtyOrderedTotal > 0) { orders.Add(order); } } } return(orders); }
public IFacadeUpdateResult <ShipToData> SaveShipTo(ShipToDto dto) { UnitOfWork.BeginTransaction(); IFacadeUpdateResult <ShipToData> result = ShipToSystem.SaveShipTo(dto); if (result.IsSuccessful) { UnitOfWork.CommitTransaction(); } else { UnitOfWork.RollbackTransaction(); } return(result); }
protected void ucIList_InstanceRowSaving(object sender, InstanceRowSavingEventArgs e) { using (IUnitOfWork uow = UnitOfWorkFactory.Instance.Start(DataStoreResolver.CRMDataStoreKey)) { ShipToDto project = e.Instance as ShipToDto; ShipToFacade facade = new ShipToFacade(uow); IFacadeUpdateResult <ShipToData> result = facade.SaveShipTo(project); e.IsSuccessful = result.IsSuccessful; if (result.IsSuccessful) { // Refresh whole list RetrieveInstances(facade); } else { // Deal with Update result ProcUpdateResult(result.ValidationResult, result.Exception); } } }
protected void ucIEdit_InstanceSaving(object sender, InstanceSavingEventArgs e) { ShipToDto instance = e.Instance as ShipToDto; if (instance != null) { using (IUnitOfWork uow = UnitOfWorkFactory.Instance.Start(DataStoreResolver.CRMDataStoreKey)) { ShipToFacade facade = new ShipToFacade(uow); IFacadeUpdateResult <ShipToData> result = facade.SaveShipTo(instance); e.IsSuccessful = result.IsSuccessful; if (result.IsSuccessful) { // Refresh Instance CurrentInstance = result.ToDto <ShipToDto>(new ShipToConverter()); } else { // Deal with Update result ProcUpdateResult(result.ValidationResult, result.Exception); } } } }
protected void ucIDetail_ChildListInstanceRowSaving(object sender, InstanceRowSavingEventArgs e) { using (IUnitOfWork uow = UnitOfWorkFactory.Instance.Start(DataStoreResolver.CRMDataStoreKey)) { switch ((InstanceTypes)Enum.Parse(typeof(InstanceTypes), e.InstanceType)) { case InstanceTypes.Contact: ContactFacade facade = new ContactFacade(uow); ContactDto contactDto = e.Instance as ContactDto; contactDto.CustomerId = CurrentInstance.Id; // Save data IFacadeUpdateResult <ContactData> result = facade.SaveContact(contactDto); e.IsSuccessful = result.IsSuccessful; if (result.IsSuccessful) { // Refresh data in session CurrentInstance.Contacts = facade.RetrieveContactsByCustomer(CurrentInstance.Id, new ContactConverter()); } else { ProcUpdateResult(result.ValidationResult, result.Exception); } break; case InstanceTypes.ScheduleEvent: ScheduleEventFacade facade2 = new ScheduleEventFacade(uow); ScheduleEventDto eventDto = e.Instance as ScheduleEventDto; eventDto.ObjectId = CurrentInstance.Id; eventDto.ObjectTypeId = (int)EventObjectTypes.Customer; // Save data IFacadeUpdateResult <ScheduleEventData> result2 = facade2.SaveScheduleEvent(eventDto); e.IsSuccessful = result2.IsSuccessful; if (result2.IsSuccessful) { // Refresh data in session CurrentInstance.ScheduleEvents = facade2.RetrieveScheduleEventsByCustomer(CurrentInstance.Id, new ScheduleEventConverter()); } else { ProcUpdateResult(result2.ValidationResult, result2.Exception); } break; case InstanceTypes.ShipTo: ShipToFacade facade3 = new ShipToFacade(uow); ShipToDto shipToDto = e.Instance as ShipToDto; shipToDto.CustomerId = CurrentInstance.Id; // Save data IFacadeUpdateResult <ShipToData> result3 = facade3.SaveShipTo(shipToDto); e.IsSuccessful = result3.IsSuccessful; if (result3.IsSuccessful) { // Refresh data in session CurrentInstance.ShipTos = facade3.RetrieveShipTosByCustomer(CurrentInstance.Id, new ShipToConverter()); } else { ProcUpdateResult(result3.ValidationResult, result3.Exception); } break; } } }