Ejemplo n.º 1
0
        public static CustomFieldAnswer CustomFieldAnswer(int?counter)
        {
            var rtValue = new CustomFieldAnswer();

            rtValue.Answer      = "Answer" + counter.Extra();
            rtValue.CustomField = new CustomField();
            rtValue.Order       = new Order();

            return(rtValue);
        }
Ejemplo n.º 2
0
        public ICommandResult Handle(SendCustomFormRequest command)
        {
            if (!command.IsValid())
            {
                return(new CommandResult(false, "Request inválida", command));
            }

            var customFormAnswer = new CustomFormAnswer(command.CustomFormId, _tenant.Id);

            AddNotifications(customFormAnswer);

            foreach (var fieldCommand in command.Fields)
            {
                var customField = _customFieldRepository.Get(fieldCommand.CustomFieldId);

                if (customField.Mandatory)
                {
                    if (!customField.HasOptions())
                    {
                        if (string.IsNullOrEmpty(fieldCommand.Answer))
                        {
                            AddNotification("Answer", $"O Campo {customField.Name} é obrigatório");
                        }
                    }
                    else
                    {
                        if (fieldCommand.CustomFieldOptionId == null)
                        {
                            AddNotification("CustomFieldOptionId", $"O Campo {customField.Name} deve ser selecionado.");
                        }
                    }
                }


                var customFieldAnswer = new CustomFieldAnswer(fieldCommand.CustomFieldId, fieldCommand?.Answer, customFormAnswer.Id, fieldCommand?.CustomFieldOptionId, _tenant.Id);

                AddNotifications(customFieldAnswer.Notifications);

                customFormAnswer.AddField(customFieldAnswer);
            }

            if (Valid)
            {
                _customFormAnswerRepository.Save(customFormAnswer);
            }

            if (Valid)
            {
                return(new CommandResult(true, "Resposta do formulário cadastrada com sucesso", new { Id = customFormAnswer.Id }));
            }
            else
            {
                return(new CommandResult(false, "Erro ao cadastrar resposta do formulário", Notifications));
            }
        }
Ejemplo n.º 3
0
        public void Deve_Criar_Uma_Resposta_De_Formulario()
        {
            Deve_Criar_Campos_Do_Formulario_Com_Opcoes();
            var customFormAnswer = new CustomFormAnswer(_customForm.Id, _tenant.Id);

            foreach (var customFormField in _customForm.Fields)
            {
                var option            = customFormField.Options.FirstOrDefault();
                var answer            = customFormField.HasOptions() ? option?.Id.ToString() : "Resposta Pergunta";
                var customFieldAnswer = new CustomFieldAnswer(customFormField.Id, answer, customFormAnswer.Id, option?.Id, _tenant.Id);
                customFormAnswer.AddField(customFieldAnswer);
                Assert.IsTrue(customFieldAnswer.Valid);
                Assert.AreEqual(_tenant.Id, customFieldAnswer.TenantId);
                Assert.AreEqual(customFieldAnswer.EntityStatus, EntityStatus.Activated);
            }
            Assert.IsTrue(customFormAnswer.Valid);
            Assert.AreEqual(_tenant.Id, customFormAnswer.TenantId);
            Assert.AreEqual(customFormAnswer.EntityStatus, EntityStatus.Activated);
        }
 public void Update(CustomFieldAnswer entity)
 {
     Context.Entry(entity).State = EntityState.Modified;
 }
 public void Save(CustomFieldAnswer entity)
 {
     Context.CustomFieldAnswers.Add(entity);
 }
Ejemplo n.º 6
0
        public static CustomFieldAnswer CustomFieldAnswer(int? counter)
        {
            var rtValue = new CustomFieldAnswer();
            rtValue.Answer = "Answer" + counter.Extra();
            rtValue.CustomField = new CustomField();
            rtValue.Order = new Order();

            return rtValue;
        }
Ejemplo n.º 7
0
        private void BindOrderModel(Order order, OrderViewModel model, bool includeLineItemsAndSplits = false)
        {
            var workgroup = _repositoryFactory.WorkgroupRepository.GetById(model.Workgroup);

            //TODO: automapper?
            order.Vendor = model.Vendor == 0 ? null : _repositoryFactory.WorkgroupVendorRepository.GetById(model.Vendor);
            order.Address = _repositoryFactory.WorkgroupAddressRepository.GetById(model.ShipAddress);
            order.ShippingType = _repositoryFactory.ShippingTypeRepository.GetById(model.ShippingType);
            order.DateNeeded = model.DateNeeded;
            order.AllowBackorder = model.AllowBackorder;
            order.Workgroup = workgroup;
            order.Organization = workgroup.PrimaryOrganization; //TODO: why is this needed?
            order.DeliverTo = model.ShipTo;
            order.DeliverToEmail = model.ShipEmail;
            order.DeliverToPhone = model.ShipPhone;
            order.OrderType = order.OrderType ?? _repositoryFactory.OrderTypeRepository.GetById(OrderType.Types.OrderRequest);
            order.CreatedBy = order.CreatedBy ?? _repositoryFactory.UserRepository.GetById(CurrentUser.Identity.Name); //Only replace created by if it doesn't already exist
            order.Justification = model.Justification;
            order.BusinessPurpose = model.BusinessPurpose;
            order.RequestType = model.RequestType;

            if (!string.IsNullOrWhiteSpace(model.Comments))
            {
                var comment = new OrderComment
                {
                    DateCreated = DateTime.UtcNow.ToPacificTime(),
                    User = _repositoryFactory.UserRepository.GetById(CurrentUser.Identity.Name),
                    Text = model.Comments
                };

                order.AddOrderComment(comment);
            }

            if (model.CustomFields != null)
            {
                order.CustomFieldAnswers.Clear();

                foreach (var customField in model.CustomFields.Where(x => !string.IsNullOrWhiteSpace(x.Answer)))
                {
                    var answer = new CustomFieldAnswer
                    {
                        Answer = customField.Answer,
                        CustomField = _repositoryFactory.CustomFieldRepository.GetById(customField.Id)
                    };

                    order.AddCustomAnswer(answer);
                }
            }

            if (model.Restricted != null && model.Restricted.IsRestricted)
            {
                var restricted = new ControlledSubstanceInformation
                {

                    ClassSchedule = model.Restricted.Class,
                    Custodian = model.Restricted.Custodian,
                    EndUser = model.Restricted.Users,
                    StorageSite = model.Restricted.StorageSite,
                    Use = model.Restricted.Use,
                    PharmaceuticalGrade = model.Restricted.PharmaceuticalGrade
                };

                order.SetAuthorizationInfo(restricted);
            }
            else
            {
                order.ClearAuthorizationInfo();
            }

            if (includeLineItemsAndSplits)
            {
                _bugTrackingService.CheckForClearedOutSubAccounts(order, model.Splits, model);

                decimal number;
                order.EstimatedTax = decimal.TryParse(model.Tax != null ? model.Tax.TrimEnd('%') : null, out number) ? number : order.EstimatedTax;
                order.ShippingAmount = decimal.TryParse(model.Shipping != null ? model.Shipping.TrimStart('$') : null, out number) ? number : order.ShippingAmount;
                order.FreightAmount = decimal.TryParse(model.Freight != null ? model.Freight.TrimStart('$') : null, out number) ? number : order.FreightAmount;

                order.LineItems.Clear(); //replace line items and splits
                order.Splits.Clear();

                //Add in line items
                foreach (var lineItem in model.Items)
                {
                    if (lineItem.IsValid())
                    {
                        Commodity commodity = null;
                        if (!string.IsNullOrWhiteSpace(lineItem.CommodityCode))
                        {
                            commodity = _repositoryFactory.CommodityRepository.Queryable.SingleOrDefault(a => a.Id == lineItem.CommodityCode && a.IsActive);
                        }

                        //TODO: could use automapper later, but need to do validation
                        var orderLineItem = new LineItem
                        {
                            CatalogNumber = lineItem.CatalogNumber,
                            Commodity = commodity,
                            Description = lineItem.Description,
                            Notes = lineItem.Notes,
                            Quantity = decimal.Parse(lineItem.Quantity),
                            Unit = lineItem.Units,//TODO: shouldn't this link to UOM?
                            UnitPrice = decimal.Parse(lineItem.Price),
                            Url = lineItem.Url
                        };

                        order.AddLineItem(orderLineItem);

                        if (model.SplitType == OrderViewModel.SplitTypes.Line)
                        {
                            var lineItemId = lineItem.Id;

                            //Go through each split created for this line item
                            foreach (var split in model.Splits.Where(x => x.LineItemId == lineItemId))
                            {
                                if (split.IsValid())
                                {
                                    order.AddSplit(new Split
                                    {
                                        Account = split.Account,
                                        Amount = decimal.Parse(split.Amount),
                                        LineItem = orderLineItem,
                                        SubAccount = split.SubAccount,
                                        Project = split.Project
                                    });
                                }
                            }
                        }
                    }
                }

                //TODO: note that I am not checking an order split actually has valid splits, or that they add to the total.
                if (model.SplitType == OrderViewModel.SplitTypes.Order)
                {
                    foreach (var split in model.Splits)
                    {
                        if (split.IsValid())
                        {
                            order.AddSplit(new Split
                            {
                                Account = split.Account,
                                Amount = decimal.Parse(split.Amount),
                                SubAccount = split.SubAccount,
                                Project = split.Project
                            });
                        }
                    }
                }
                else if (model.SplitType == OrderViewModel.SplitTypes.None)
                {
                    order.AddSplit(new Split { Amount = order.Total(), Account = model.Account, SubAccount = model.SubAccount, Project = model.Project }); //Order with "no" splits get one split for the full amount
                }

                order.TotalFromDb = order.Total();
                order.LineItemSummary = order.GenerateLineItemSummary();
            }
        }