public async Task <ValidationResult <Order> > CreateOrder(int mobileId, int personnelId, List <int> sellerIds, int shippingAddressId)
        {
            ValidationResult <Order> validationResult = new ValidationResult <Order>();

            try
            {
                var order = new Order()
                {
                    CreatedDateTime   = DateTime.Now,
                    MobileId          = mobileId,
                    OrderGuid         = Guid.NewGuid(),
                    OrderStateId      = (int)OrderState.Requested,
                    PersonnelId       = personnelId,
                    ShippingAddressId = shippingAddressId
                };
                var orderEntity = await _dataService.CreateGetAsync(order);

                var sellerOrderList = sellerIds.Select(seller => new SellerOrder()
                {
                    OrderId  = orderEntity.OrderId,
                    SellerId = seller
                }).ToList();
                await _dataService.CreateRangeAsync(sellerOrderList);

                var customerPersonnel = await _personnelDataService.RetrieveByIdAsync <Personnel>(personnelId);

                var sellers = await _sellerBusinessService.RetrieveSellers(sellerIds);

                //var personnelData = await _personnelDataService.RetrieveByIdAsync<Personnel>(mobileId.PersonnelId);
                var mobileData = await _mobileDataService.RetrieveByIdAsync <Entity.Mobile>(mobileId);
                await SendOrderEmailToCustomer(orderEntity, customerPersonnel, mobileData);
                await SendOrderEmailToSellers(orderEntity, sellers, customerPersonnel, mobileData);

                SendOrderSms(order, sellers, customerPersonnel, mobileData);
                validationResult.Succeeded = true;
            }
            catch (Exception ex)
            {
                validationResult.Succeeded = false;
                validationResult.Errors    = new List <string> {
                    ex.InnerMessage()
                };
                validationResult.Exception = ex;
            }
            return(validationResult);
        }
示例#2
0
        public async Task <ValidationResult <Personnel> > RetrievePersonnel(int personnelId)
        {
            var personnel = await _dataService.RetrieveByIdAsync <Personnel>(personnelId);

            if (personnel != null)
            {
                var validationResult = new ValidationResult <Personnel>
                {
                    Entity    = personnel,
                    Succeeded = true
                };
                return(validationResult);
            }

            return(new ValidationResult <Personnel>
            {
                Succeeded = false,
                Errors = new[] { string.Format("No Worker found with Id: {0}", personnelId) }
            });
        }