示例#1
0
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                var costService = new CostService();

                var cost = new BI_K3_Costs()
                {
                    BI_CostID = int.Parse(collection["BI_CostID"]),
                    Role_Type = collection["role_type"],
                    Role_Name = collection["role_name"]
                };
                if (collection["daily_cost"] != null)
                {
                    cost.Daily_Cost = decimal.Parse(collection["daily_cost"]);
                }
                if (collection["hourly_cost"] != null)
                {
                    cost.Hourly_Cost = decimal.Parse(collection["hourly_cost"]);
                }
                costService.UpdateCost(cost);
                return(RedirectToAction("Index"));
            }
            catch (Exception exception)
            {
                return(View());
            }
        }
示例#2
0
            public async Task UpdateCost_WhenSupportingDocumentsHaveChanged()
            {
                // Arrange
                var    costId          = Guid.NewGuid();
                var    stageRevisionId = Guid.NewGuid();
                var    documentId      = Guid.NewGuid();
                string data            = "{\"smoId\": null, \"title\": \"asdf\", \"isAIPE\": false, \"campaign\": \"15xStronger (Pantene)\", \"costType\": \"Production\", \"projectId\": \"5aa6958836d1a002c68a1424\", \"costNumber\": \"PGI0005D0000001\", \"contentType\": {\"id\": \"0cbdb306-f3bd-4d2e-a70c-6cfe3b3dc41b\", \"key\": \"Digital\", \"value\": \"Digital\", \"created\": \"2018-02-13T14:42:56.684202\", \"visible\": true, \"modified\": \"2018-02-13T14:42:56.684201\", \"projects\": null, \"createdById\": \"77681eb0-fc0d-44cf-83a0-36d51851e9ae\", \"dictionaryId\": \"a97b2773-66eb-4d07-9bc5-8af5bf784d53\"}, \"budgetRegion\": {\"id\": \"7291b9c2-92cd-488b-8c68-f03f339b3c18\", \"key\": \"EUROPE AREA\", \"name\": \"Europe\"}, \"organisation\": {\"id\": \"fe8f1631-0c15-44be-a5e5-16d42fb62d2f\", \"key\": \"BFO\", \"value\": \"BFO\", \"created\": \"2018-02-13T14:42:56.696786\", \"visible\": true, \"modified\": \"2018-02-13T14:42:56.696785\", \"projects\": null, \"createdById\": \"77681eb0-fc0d-44cf-83a0-36d51851e9ae\", \"dictionaryId\": \"f1ce7c45-c502-488f-b33c-15554b60c1f1\"}, \"initialBudget\": 50000, \"agencyCurrency\": \"USD\", \"agencyProducer\": [\"Abby Jenkins (Leo Burnett)\"], \"IsCurrencyChanged\": false}";
                var    cost            = new Cost
                {
                    Id    = costId,
                    Owner = new CostUser(),
                    LatestCostStageRevision = new CostStageRevision()
                    {
                        Id = stageRevisionId,
                        SupportingDocuments = new List <SupportingDocument>()
                        {
                            new SupportingDocument()
                            {
                                Id = documentId,
                                CostStageRevisionId = stageRevisionId,
                                Key  = "file1 key",
                                Name = "file1 name",
                            },
                            new SupportingDocument()
                            {
                                Id = Guid.NewGuid(),
                                CostStageRevisionId = stageRevisionId,
                            }
                        },
                        StageDetails = new CustomFormData()
                        {
                            Data = data,
                        },
                        ProductDetails = new CustomFormData()
                        {
                            Data = data,
                        },
                        CostStage = new CostStage()
                        {
                            Key  = String.Empty,
                            Name = String.Empty,
                        },
                    },
                };

                CostBuilderMock.Setup(cb => cb.UpdateCost(It.IsAny <UserIdentity>(), It.IsAny <Guid>(), It.IsAny <Guid>(), It.IsAny <CostType>(), It.IsAny <StageDetails>(), It.IsAny <ProductionDetail>()))
                .ReturnsAsync(new plugins.PG.Builders.Cost.UpdateCostResponse()
                {
                    StageDetails          = cost.LatestCostStageRevision.StageDetails,
                    ProductionDetails     = cost.LatestCostStageRevision.ProductDetails,
                    CurrentCostStageModel = new CostStageModel()
                    {
                        Key       = "FirstStage Key",
                        Name      = "FirstStage Name",
                        Order     = 1,
                        Revisions = new[]
                        {
                            new CostStageRevisionModel
                            {
                                Name                = "FirstStage Key",
                                Status              = CostStageRevisionStatus.Draft,
                                StageDetails        = data,
                                SupportingDocuments = new []
                                {
                                    new SupportingDocumentModel()
                                    {
                                        Key  = "file1 key",
                                        Name = "file1 name",
                                    },
                                    new SupportingDocumentModel(),
                                }
                            }
                        }
                    }
                });

                EFContext.Cost.Add(cost);
                EFContext.SaveChanges();
                cost.LatestCostStageRevision.SupportingDocuments.Add(new SupportingDocument());

                // Act
                await CostService.UpdateCost(costId, User, new UpdateCostModel());

                // Assert
                var documents = EFContext.SupportingDocument.Where(sd => sd.CostStageRevisionId == stageRevisionId).ToList();

                documents.Count.Should().Be(3);
                documents.Count(sd => sd.Id == documentId).Should().Be(1);
            }