Пример #1
0
        public async Task <ApplicationResult> SubmitInitiationForm(FormDetailModel form)
        {
            var validator           = new FormDetailModelValidator();
            ValidationResult result = await validator.ValidateAsync(form);

            if (result.IsValid)
            {
                if (form.Action == CustomerFormStatus.Approved)
                {
                    return(await ApproveInitiationForm(form.CustomerDetailFormId, form.InitiationModel !.AdminSignature));
                }
                if (form.Action == CustomerFormStatus.Denied)
                {
                    return(await DenyInitiationForm(form.Customer.Id, form.CustomerDetailFormId));
                }
                if (form.Action == CustomerFormStatus.AwaitingCustomerSupervisorApproval)
                {
                    CustomerForm customerForm   = _mapper.Map <CustomerForm>(form);
                    int          customerFormId = await _service.SubmitCustomerForm(customerForm);

                    await _eventService.CreateEvent(EntityEventType.Customer, form.Customer.Id, Events.Customer.SubmittedInitiationForm);
                    await UpdateFormStatus(form.Customer.Id, customerFormId, form.Action);

                    await _notificationManager.ProcessExternalMtaNotification(form);
                }
                return(ApplicationResult.Success("Form submitted", form.CustomerDetailFormId));
            }
            return(ApplicationResult.Error(result));
        }
Пример #2
0
        public async Task <ApplicationResult> Edit(ShipmentDetailModel model)
        {
            ShipmentDetailModelValidator validator = new ShipmentDetailModelValidator();
            ValidationResult             result    = await validator.ValidateAsync(model);

            if (result.IsValid)
            {
                Shipment shipment = _mapper.Map <Shipment>(model);
                if (shipment.Status == ShipmentStatus.Cancelled)
                {
                    shipment.IsDeleted = true;
                }
                int id = await _service.Update(shipment);

                await _eventManager.CreateEvent(EntityEventType.Shipping, id, Events.Shipment.Edited);

                if (model.Status == ShipmentStatus.Cancelled)
                {
                    await _eventManager.CreateEvent(EntityEventType.Shipping, model.Id, Events.Shipment.Cancelled);
                }
                else if (model.Status == ShipmentStatus.Shipped)
                {
                    await _eventManager.CreateEvent(EntityEventType.Shipping, model.Id, Events.Shipment.Shipped);
                }
                return(ApplicationResult.Success("Shipment edited", id));
            }
            return(ApplicationResult.Error(result));
        }
Пример #3
0
        public async Task <ApplicationResult> UpdateFormStatus(int customerId, int customerFormId, CustomerFormStatus status)
        {
            await _eventService.CreateEvent(EntityEventType.Customer, customerId, Events.Customer.FormStatusChanged);

            await _service.UpdateCustomerFormStatus(customerFormId, status);

            return(ApplicationResult.Success("Form status updated", status));
        }
Пример #4
0
        public async Task <ApplicationResult> Edit(ItemDetailModel model)
        {
            ItemDetailModelValidator validator = new ItemDetailModelValidator();
            ValidationResult         result    = await validator.ValidateAsync(model);

            if (result.IsValid)
            {
                Item item = _mapper.Map <Item>(model);
                int  id   = await _service.Update(item);

                return(ApplicationResult.Success("Item updated", id));
            }
            return(ApplicationResult.Error(result));
        }
Пример #5
0
        public async Task <ApplicationResult> ApplyItemConfigurations(OrderDetailModel order)
        {
            foreach (OrderItemDetailModel item in order.Cart)
            {
                ItemConfigurationDetailModel?config = await GetItemConfiguration(item.Item.Id, order.Customer.Id, order.Customer.ParentCustomerId, item.Quantity);

                if (config == null)
                {
                    return(ApplicationResult.Error("Failed to find item configuration for customer"));
                }
                item.ItemConfiguration   = config;
                item.ItemConfigurationId = config.Id;
            }
            return(ApplicationResult.Success());
        }
Пример #6
0
        public async Task <ApplicationResult> SubmitInitiationFormSignature(string supervisorEmailAddress, Guid formIdentifier, FormInitiationSignatureModel signature)
        {
            FormDetailModel?form = await GetInitiationForm(supervisorEmailAddress, formIdentifier);

            if (form == null || form.InitiationModel == null)
            {
                return(ApplicationResult.Error("Unable to find form for supervisor email"));
            }
            form.InitiationModel.CustomerAdminSignature = signature;
            CustomerForm customerForm = _mapper.Map <CustomerForm>(form);
            await _service.SubmitCustomerForm(customerForm);

            await UpdateFormStatus(form.Customer.Id, form.CustomerDetailFormId, CustomerFormStatus.AwaitingAdminApproval);

            return(ApplicationResult.Success("Form signed", form.CustomerDetailFormId));
        }
Пример #7
0
        public async Task <ApplicationResult> Create(ShipmentDetailModel model)
        {
            ShipmentDetailModelValidator validator = new ShipmentDetailModelValidator();
            ValidationResult             result    = await validator.ValidateAsync(model);

            if (result.IsValid)
            {
                Shipment shipment = _mapper.Map <Shipment>(model);
                int      id       = await _service.Create(shipment);

                await _eventManager.CreateEvent(EntityEventType.Shipping, id, Events.Shipment.Created);

                return(ApplicationResult.Success("Shipment created", id));
            }
            return(ApplicationResult.Error(result));
        }
Пример #8
0
        private async Task <ApplicationResult> ApproveInitiationForm(int formId, FormInitiationSignatureModel signature)
        {
            FormDetailModel?form = await GetInitiationForm(formId);

            if (form == null)
            {
                return(ApplicationResult.Error("Unable to find form for admin approval email"));
            }
            form.InitiationModel !.AdminSignature = signature;
            CustomerForm customerForm = _mapper.Map <CustomerForm>(form);
            await _service.SubmitCustomerForm(customerForm);

            await UpdateFormStatus(form.Customer.Id, form.CustomerDetailFormId, CustomerFormStatus.Approved);
            await UpdateCustomerFromInitiationForm(form);

            return(ApplicationResult.Success("Form signed", form.CustomerDetailFormId));
        }
Пример #9
0
        public async Task <ApplicationResult> Create(OrderDetailModel model)
        {
            OrderDetailModelValidator validator = new OrderDetailModelValidator();
            ValidationResult          result    = await validator.ValidateAsync(model);

            if (result.IsValid)
            {
                Order order = _mapper.Map <Order>(model);
                int   id    = await _service.Create(order);

                await _eventService.CreateEvent(EntityEventType.Order, id, Events.Order.Created);

                if (order.Status == OrderStatus.Sent)
                {
                    await _eventService.CreateEvent(EntityEventType.Order, id, Events.Order.Sent);
                }
                return(ApplicationResult.Success("Order created", id));
            }
            return(ApplicationResult.Error(result));
        }
Пример #10
0
        public async Task <ApplicationResult> Edit(CustomerDetailModel model)
        {
            var validator           = new CustomerDetailModelValidator();
            ValidationResult result = await validator.ValidateAsync(model);

            if (result.IsValid)
            {
                try {
                    Customer customer = _mapper.Map <Customer>(model);
                    int      id       = await _service.Update(customer);

                    await _eventService.CreateEvent(EntityEventType.Customer, customer.Id, Events.Customer.Edited);

                    return(ApplicationResult.Success("Customer updated successfully", id));
                }
                catch (Exception ex) {
                    _logger.LogError(ex, "Failed to update customer");
                    return(ApplicationResult.Error(ex));
                }
            }
            return(ApplicationResult.Error(result));
        }
Пример #11
0
        public async Task <ApplicationResult> DenyInitiationForm(int customerId, int formId)
        {
            await UpdateFormStatus(customerId, formId, CustomerFormStatus.Denied);

            return(ApplicationResult.Success("Initiation Form Denied", formId));
        }
Пример #12
0
        public async Task <ApplicationResult> Delete(int id)
        {
            int recordsAffected = await _service.Delete(id);

            return(ApplicationResult.Success("Item deleted", recordsAffected));
        }