Esempio n. 1
0
        public override void Execute()
        {
            var repository = new MilestoneRepository();
            var milestones = repository.GetMilestonesForComingDays(_amtDays);
            var builder = new StringBuilder();
            var mailer = new MailSender();

            foreach (var ms in milestones)
            {
                builder.Append("\n***********************************************");
                builder.Append(string.Format("\n{0} - {1} - {2} {3}:", ms.Release.Title, ms.Title, ms.Date.ToDutchString(), ms.Time));
                var statuses = repository.GetActivityStatusForMilestones(ms);
                builder.Append("\n----------------------------------------------");
                foreach (var state in statuses)
                {

                    builder.Append(string.Format("\n{0}: {1}", "Project", state.Project.Title));
                    builder.Append(string.Format("\n{0} - {1} - {2} hrs remaining", state.Deliverable.Title, state.Activity.Title, state.HoursRemaining));
                    builder.Append("\n----------------------------------------------");
                }

                builder.Append("\n***********************************************");
                builder.Append("\n\n");

            }
            var content = builder.ToString();
            mailer.SendMail(_emailAddress, "Milestones coming up", content);
        }
Esempio n. 2
0
        public void ShouldReturnASingleMilestoneById()
        {
            //Arrange
            string expectedSQLStatement = "SELECT * FROM saver.Milestones WHERE Id = @Id;";

            Model.Milestone expectedMilestone = new Model.Milestone(1, 100, "Testing 1", null);

            //Setup the mocks
            mockDataAccess.Setup
            (
                da => da.ExecuteQuery <Model.Milestone>
                (
                    It.Is <string>(val => val.Equals(expectedSQLStatement)),
                    It.Is <Dictionary <string, object> >(val => (int)val["Id"] == expectedMilestone.Id)
                )
            )
            .Returns(new Model.Milestone[] { expectedMilestone });
            mockSqlStringService.Setup(ss => ss.GetSqlFromResource(It.IsAny <string>())).Returns(expectedSQLStatement);

            IMilestoneRepository repository = new MilestoneRepository(mockDataAccess.Object, mockSqlStringService.Object);

            //Act
            Model.Milestone returnedMilestone = repository.Get(expectedMilestone.Id);

            //Assert
            returnedMilestone.Should().NotBeNull();
            returnedMilestone.Should().BeEquivalentTo(expectedMilestone);
        }
Esempio n. 3
0
 public MilestoneRepositoryTests()
 {
     _request        = Substitute.For <IRequest>();
     _requestFactory = Substitute.For <IRequestFactory>();
     _requestFactory.Create(Arg.Any <string>(), Arg.Any <Method>(), Arg.Any <bool>()).Returns(_request);
     _sut = new MilestoneRepository(_requestFactory);
 }
Esempio n. 4
0
        public void ShouldUpdateMilestoneWithNewInformation()
        {
            int expectedMilestoneId = 2;

            Model.Milestone updatedMilestone     = new Model.Milestone(2, 250d, null, null);
            string          expectedSqlStatement = "UPDATE saver.milestones SET target = @Target, DateMet = @DateMet, Description = @Description WHERE Id = @Id";

            mockDataAccess.Setup
            (
                da => da.ExecuteQueryWithGenericParameterType <Model.Milestone>
                (
                    It.Is <string>(val => val.Equals(expectedSqlStatement)),
                    It.IsAny <Model.Milestone>()
                )
            ).Returns(new Model.Milestone[] { updatedMilestone });
            mockSqlStringService.Setup(ss => ss.GetSqlFromResource(It.IsAny <string>())).Returns(expectedSqlStatement);


            IMilestoneRepository repository = new MilestoneRepository(mockDataAccess.Object, mockSqlStringService.Object);

            //Act
            Model.Milestone milestone = repository.Update(expectedMilestoneId, updatedMilestone);

            //Assert
            milestone.Should().NotBeNull();
            milestone.Id.Should().Be(expectedMilestoneId);
            milestone.Should().BeEquivalentTo(updatedMilestone);
        }
Esempio n. 5
0
        public void ShouldReturnAllKnownMilestonesForSpecificGoal()
        {
            //Arrange
            int    goalId = 1;
            string expectedSQLStatement = "SELECT * FROM saver.Milestones WHERE goalid = @GoalId ORDER BY id ASC;";
            IEnumerable <Model.Milestone> expectedMilestones = new List <Model.Milestone>()
            {
                new Model.Milestone(1, 100, "Testing 1", null),
                new Model.Milestone(1, 200, "Testing 2", null),
                new Model.Milestone(1, 300, "Testing 3", null),
                new Model.Milestone(1, 400, "Testing 4", null),
                new Model.Milestone(1, 500, "Testing 5", null)
            };

            //Setup the mocks
            mockDataAccess.Setup(da => da.ExecuteQuery <Model.Milestone>
                                 (
                                     It.Is <string>(val => val.Equals(expectedSQLStatement)),
                                     It.Is <Dictionary <string, object> >(val => (int)val["GoalId"] == goalId)
                                 )
                                 ).Returns(expectedMilestones);
            mockSqlStringService.Setup(ss => ss.GetSqlFromResource(It.IsAny <string>())).Returns(expectedSQLStatement);

            IMilestoneRepository repository = new MilestoneRepository(mockDataAccess.Object, mockSqlStringService.Object);

            //Act
            IEnumerable <Model.Milestone> returnedMilestones = repository.GetForGoal(goalId);

            //Assert
            returnedMilestones.Should().NotBeNull();
            returnedMilestones.Count().Should().Be(5);
            returnedMilestones.Should().Contain(expectedMilestones);
        }
Esempio n. 6
0
        public void ShouldDeleteAMilestoneWithAGivenIDAndReturn()
        {
            int milestoneId = 2;

            Model.Milestone deletedMilestone     = new Model.Milestone(2, 250d, null, null);
            string          expectedSqlStatement = "DELETE FROM saver.milestons... etc";

            mockDataAccess.Setup
            (
                da => da.ExecuteQueryWithGenericParameterType <Model.Milestone>
                (
                    It.Is <string>(val => val.Equals(expectedSqlStatement)),
                    It.IsAny <object>()
                )
            ).Returns(new Model.Milestone[] { deletedMilestone });
            mockSqlStringService.Setup(ss => ss.GetSqlFromResource(It.IsAny <string>())).Returns(expectedSqlStatement);


            IMilestoneRepository repository = new MilestoneRepository(mockDataAccess.Object, mockSqlStringService.Object);

            //Act
            Model.Milestone milestone = repository.Delete(milestoneId);

            //Assert
            milestone.Should().NotBeNull();
            milestone.Id.Should().Be(milestoneId);
            milestone.Should().BeEquivalentTo(deletedMilestone);
        }
Esempio n. 7
0
 public HttpResponseMessage Get()
 {
     try
     {
         return(Request.CreateResponse(HttpStatusCode.OK, MilestoneRepository.ReadAll()));
     }
     catch (Exception exc)
     {
         return(Request.CreateResponse(HttpStatusCode.BadRequest, "Generic error happened."));
     }
 }
Esempio n. 8
0
        public async Task MilestoneRepository_GetAllAsync_ReturnsAllValues()
        {
            await using var context = new TimeTrackingDbContext(_dbOptions);
            var milestoneRepository = new MilestoneRepository(context);
            var expected            = MilestonesDbSet.Get();

            var actual = await milestoneRepository.GetAllAsync();

            Assert.That(actual.OrderBy(x => x.Id), Is.EqualTo(expected.OrderBy(x => x.Id))
                        .Using(EqualityComparers.MilestoneComparer));
        }
Esempio n. 9
0
        public async Task MilestoneRepository_UpdateAsync_UpdateEntity()
        {
            await using var context = new TimeTrackingDbContext(_dbOptions);
            var milestoneRepository = new MilestoneRepository(context);
            var entityToUpdate      = MilestonesDbSet.Get().First();

            entityToUpdate.Description = "New description";

            var actual = await milestoneRepository.UpdateAsync(entityToUpdate);

            Assert.That(actual, Is.EqualTo(entityToUpdate).Using(EqualityComparers.MilestoneComparer));
        }
Esempio n. 10
0
        public async Task MilestoneRepository_GetById_ShouldReturnCorrectItem(string id)
        {
            var guidId = Guid.Parse(id);

            await using var context = new TimeTrackingDbContext(_dbOptions);
            var expected            = MilestonesDbSet.Get().First(x => x.Id == guidId);
            var milestoneRepository = new MilestoneRepository(context);

            var actual = await milestoneRepository.GetByIdAsync(guidId);

            Assert.That(actual, Is.EqualTo(expected).Using(EqualityComparers.MilestoneComparer));
        }
Esempio n. 11
0
        public async Task MilestoneRepository_DeleteAsync_DeletesEntity()
        {
            var guidId         = Guid.Parse("9245950B-0F82-4B9E-9AF7-DEC9ACF171FA");
            var entityToDelete = MilestonesDbSet.Get().First(x => x.Id == guidId);
            var expectedCount  = MilestonesDbSet.Get().ToList().Count - 1;

            await using var context = new TimeTrackingDbContext(_dbOptions);
            var milestoneRepository = new MilestoneRepository(context);

            await milestoneRepository.DeleteAsync(entityToDelete);

            context.Milestones.Should().HaveCount(expectedCount);
        }
 /// <summary>
 /// Initializes a new instance of the UnitOfWork class.
 /// </summary>
 /// <param name="context">The object context</param>
 public UnitOfWork()
 {
     _repositories = new Dictionary <string, object>();
     Colors        = new ColorRepository(_dbContext);
     Comments      = new CommentRepository(_dbContext);
     Labels        = new LabelRepository(_dbContext);
     Milestones    = new MilestoneRepository(_dbContext);
     Priorities    = new PriorityRepository(_dbContext);
     Projects      = new ProjectRepository(_dbContext);
     Statuses      = new StatusRepository(_dbContext);
     Tasks         = new TaskRepository(_dbContext);
     Users         = new UserRepository(_dbContext);
 }
Esempio n. 13
0
        public async Task MilestoneRepository_AddAsync_AddsValueToDatabase()
        {
            var expectedCount = MilestonesDbSet.Get().ToList().Count + 1;
            var entityToAdd   = MilestonesDbSet.MilestoneBuilder().Create();

            await using var context = new TimeTrackingDbContext(_dbOptions);
            var milestoneRepository = new MilestoneRepository(context);

            await milestoneRepository.AddAsync(entityToAdd);

            context.Milestones.Should().HaveCount(expectedCount);
            var entityFound = await context.Milestones.FindAsync(entityToAdd.Id);

            Assert.That(entityFound, Is.EqualTo(entityToAdd).Using(EqualityComparers.MilestoneComparer));
        }
Esempio n. 14
0
 public HttpResponseMessage Post(MilestoneDto dto)
 {
     try
     {
         if (dto != null)
         {
             MilestoneRepository.Create(dto);
             return(Request.CreateResponse(HttpStatusCode.OK));
         }
         return(Request.CreateResponse(HttpStatusCode.BadRequest));
     }
     catch (Exception e)
     {
         return(Request.CreateResponse(HttpStatusCode.BadRequest, "Generic error happened."));
     }
 }
Esempio n. 15
0
 public HttpResponseMessage Delete(int id)
 {
     try
     {
         MilestoneRepository.Delete(id);
         return(Request.CreateResponse(HttpStatusCode.OK));
     }
     catch (ElementNotFoundException e)
     {
         return(Request.CreateResponse(HttpStatusCode.BadRequest, e.Message));
     }
     catch (Exception e)
     {
         return(Request.CreateResponse(HttpStatusCode.BadRequest, "Generic error happened."));
     }
 }
Esempio n. 16
0
        public void ShouldCreateMultipleMilestonesForAGivenGoalId()
        {
            int expectedGoalId = 1;
            List <Model.Milestone> milestones = new List <Model.Milestone>()
            {
                new Model.Milestone(100, "Testing", null),
                new Model.Milestone(200, "Testing", null),
                new Model.Milestone(300, "Testing", null)
            };
            List <Model.Milestone> createdMilestones = new List <Model.Milestone>()
            {
                new Model.Milestone(1, 100, "Testing", null),
                new Model.Milestone(2, 200, "Testing", null),
                new Model.Milestone(3, 300, "Testing", null)
            };
            string expectedSqlStatement = "INSERT INTO saver.Milestone (target, description, datemet, goalid) VALUES (@Target, @Description, @DateMet, @GoalId);";

            mockDataAccess.Setup
            (
                da => da.ExecuteWithGenericParameters
                (
                    It.Is <string>(val => val.Equals(expectedSqlStatement)),
                    It.IsAny <object>()
                )
            ).Returns(createdMilestones.Count);

            mockDataAccess.Setup
            (
                da => da.ExecuteQueryWithGenericParameterType <Model.Milestone>
                (
                    It.Is <string>(val => val.Equals(expectedSqlStatement)),
                    It.IsAny <object>()
                )
            ).Returns(createdMilestones);
            mockSqlStringService.Setup(ss => ss.GetSqlFromResource(It.IsAny <string>())).Returns(expectedSqlStatement);

            IMilestoneRepository repository = new MilestoneRepository(mockDataAccess.Object, mockSqlStringService.Object);

            //Act
            IEnumerable <Model.Milestone> returnedMilestones = repository.CreateMultipleForGoal(milestones, expectedGoalId);

            //Assert
            returnedMilestones.Should().NotBeNull();
            returnedMilestones.Count().Should().Be(createdMilestones.Count);
            returnedMilestones.Select(s => s.Id).Should().Contain(createdMilestones.Select(s => s.Id));
        }
Esempio n. 17
0
        public void ShouldCreateASingleMilestoneForAKnownGoal()
        {
            const string expectedDescription = "Testing a milestone";
            double       expectedTarget      = 230d;
            DateTime     expectedDateMet     = DateTime.Now;
            int          expectedGoalId      = 1;
            int          expectedMilestoneId = 10;

            Model.Milestone milestone = new Model.Milestone(expectedTarget, expectedDescription, expectedDateMet);
            Model.Milestone expectedResultandMilestone = new Model.Milestone(expectedMilestoneId, expectedTarget, expectedDescription, expectedDateMet);
            string          expectedSqlStatement       = "INSERT INTO saver.Milestone (target, description, datemet, goalid) VALUES (@Target, @Description, @DateMet, @GoalId);";

            mockDataAccess.Setup
            (
                da => da.ExecuteQuery <Model.Milestone>
                (
                    It.Is <string>(val => val.Equals(expectedSqlStatement)),
                    It.Is <Dictionary <string, object> >
                    (
                        val => (int)val["GoalId"] == expectedGoalId &&
                        (string)val["Description"] == expectedDescription &&
                        (double)val["Target"] == expectedTarget &&
                        (DateTime?)val["DateMet"] == expectedDateMet
                    )
                )
            ).Returns(new List <Model.Milestone>()
            {
                expectedResultandMilestone
            });
            mockSqlStringService.Setup(ss => ss.GetSqlFromResource(It.IsAny <string>())).Returns(expectedSqlStatement);

            IMilestoneRepository repository = new MilestoneRepository(mockDataAccess.Object, mockSqlStringService.Object);

            //Act
            Model.Milestone returnedMilestone = repository.CreateForGoal(milestone, expectedGoalId);

            //Assert
            returnedMilestone.Should().NotBeNull();
            returnedMilestone.Id.Should().Be(expectedMilestoneId);
            returnedMilestone.Should().BeEquivalentTo(expectedResultandMilestone);
        }
Esempio n. 18
0
        //Gen script
        public static bool GenScriptMilestone(List <ExcelRow> listExcelRows)
        {
            var milestoneRepository = new MilestoneRepository();
            var id = 0;

            using (StreamWriter stream = File.AppendText(PathFileExport))
            {
                foreach (var item in listExcelRows)
                {
                    if (!string.IsNullOrEmpty(item.IdMilestone) && !string.IsNullOrEmpty(item.MilestoneName))
                    {
                        id = Convert.ToInt32(item.IdMilestone);
                        var data = milestoneRepository.GetById(id);

                        if (data == null)
                        {
                            if (!ListIdMilestoneAdd.Contains(id))
                            {
                                ListIdMilestoneAdd.Add(id);
                                stream.WriteLine(
                                    "INSERT INTO `milestone`(`Id`,`Name`,`CreatedById`,`LastUserId`,`LastTime`,`CreatedOn`,`LastModified`) " +
                                    "VALUES ({0},'{1}',{2},{3},'{4}','{5}','{6}');",
                                    item.IdMilestone, item.MilestoneName, CreateById, LastUserId, LastTime, CreatedOn,
                                    LastModified);
                            }
                        }
                        else
                        {
                            if (!ListIdMilestoneUpdate.Contains(id))
                            {
                                ListIdMilestoneUpdate.Add(id);
                                stream.WriteLine("UPDATE `milestone` SET `Name` = '{0}' WHERE `Id` = {1};",
                                                 item.MilestoneName, id);
                            }
                        }
                    }
                }
                stream.WriteLine();
                return(true);
            }
        }
Esempio n. 19
0
        /// <summary> Creates a new <see cref="GitLabClient" /> instance. </summary>
        /// <param name="hostUri"> The GitLab server to connect to. </param>
        /// <param name="privateToken"> The private token to use when making requests to the GitLab API. </param>
        public GitLabClient(Uri hostUri, string privateToken = null)
        {
            if (hostUri == null)
            {
                throw new ArgumentNullException(nameof(hostUri));
            }

            var baseUri = new Uri(hostUri, ApiPath);

            _authenticator = new PrivateTokenAuthenticator(privateToken);
            var clientFactory  = new ClientFactory(baseUri, _authenticator);
            var requestFactory = new RequestFactory(clientFactory);

            Branches        = new BranchRepository(requestFactory);
            Builds          = new BuildRepository(requestFactory);
            BuildTriggers   = new BuildTriggerRepository(requestFactory);
            BuildVariables  = new BuildVariableRepository(requestFactory);
            Commits         = new CommitRepository(requestFactory);
            DeployKeys      = new DeployKeyRepository(requestFactory);
            Emails          = new EmailRepository(requestFactory);
            Files           = new FileRepository(requestFactory);
            GitLabLicense   = new GitLabLicenseRepository(requestFactory);
            GitLabSettings  = new GitLabSettingsRepository(requestFactory);
            Issues          = new IssueRepository(requestFactory);
            Keys            = new KeyRepository(requestFactory);
            Labels          = new LabelRepository(requestFactory);
            Licenses        = new LicenseRepository(requestFactory);
            MergeRequests   = new MergeRequestRepository(requestFactory);
            Milestones      = new MilestoneRepository(requestFactory);
            Namespaces      = new NamespaceRepository(requestFactory);
            ProjectSnippets = new ProjectSnippetRepository(requestFactory);
            Repositories    = new RepositoryRepository(requestFactory);
            Runners         = new RunnerRepository(requestFactory);
            Session         = new SessionRepository(requestFactory);
            SystemHooks     = new SystemHookRepository(requestFactory);
            Tags            = new TagRepository(requestFactory);
            Users           = new UserRepository(requestFactory);
            Projects        = new ProjectRepository(requestFactory);
            ProjectMembers  = new ProjectMemberRepository(requestFactory);
            GroupMembers    = new GroupMemberRepository(requestFactory);
        }
Esempio n. 20
0
        public async Task MilestoneRepository_GetAllPagedAsync_ReturnsAllResultsPaged()
        {
            var page = 1;
            var size = 1;

            await using var context = new TimeTrackingDbContext(_dbOptions);
            var milestoneRepository = new MilestoneRepository(context);
            var expected            = MilestonesDbSet.Get()
                                      .Skip(0)
                                      .Take(size)
                                      .OrderBy(e => e.Id)
                                      .ToList();

            var actual = await milestoneRepository.GetAllPagedAsync(page, size);

            actual.EnsurePagedResult(MilestonesDbSet.Get().ToList().Count, size, page);
            var actualItems = actual.Items.ToList();

            Assert.That(actualItems.OrderBy(e => e.Id), Is.EqualTo(expected.OrderBy(e => e.Id))
                        .Using(EqualityComparers.MilestoneComparer));
        }
Esempio n. 21
0
        public override void Execute()
        {
            var repository = new MilestoneRepository();
            var milestones = repository.GetMilestonesForComingDays(_amtDays);

            foreach (var ms in milestones)
            {
                var builder = new StringBuilder();
                var deliverables = repository.GetConfiguredDeliverables(ms);
                foreach (var del in deliverables)
                {
                    builder.Append(string.Format("* {0}", del.Title));
                    builder.Append("\n");
                }

                builder.Append("\n\n");

                var item = new CueItem(ms.Release.Title + " - " + ms.Title, ms.Date, ms.Time, builder.ToString());
                _creator.CreateVisualCue(item);
                // add notification to history table
                repository.AddNotificationToHistory(ms.Id, ms.Release.Id, "AwesomeNote");
            }
        }
Esempio n. 22
0
 // Is Milestone an entity of the Release aggregate root?
 protected List<ReleaseModels.Milestone> GetMilestonesForRelease(ReleaseModels.Release release, SqlConnection conn)
 {
     var repository = new MilestoneRepository();
     return repository.GetMilestonesForRelease(release);
 }
Esempio n. 23
0
        public ReleaseModels.Release SaveReleaseConfiguration(ReleaseConfigurationInputModel obj)
        {
            var conn = new SqlConnection("Data Source=localhost\\SQLENTERPRISE;Initial Catalog=Planner;Integrated Security=SSPI;MultipleActiveResultSets=true");
            int newId = 0;
            try
            {
                using (conn)
                {
                    conn.Open();

                    var cmd = new SqlCommand("sp_upsert_release", conn);
                    cmd.Parameters.Add("@Id", System.Data.SqlDbType.Int).Value = obj.Id;
                    cmd.Parameters.Add("@Title", System.Data.SqlDbType.VarChar).Value = obj.Title;
                    cmd.Parameters.Add("@Descr", System.Data.SqlDbType.VarChar).Value = "";// obj.Descr;
                    cmd.Parameters.Add("@StartDate", System.Data.SqlDbType.DateTime).Value = obj.StartDate.ToDateTimeFromDutchString();
                    cmd.Parameters.Add("@EndDate", System.Data.SqlDbType.DateTime).Value = obj.EndDate.ToDateTimeFromDutchString();
                    cmd.Parameters.Add("@IterationPath", System.Data.SqlDbType.VarChar).Value = obj.TfsIterationPath ?? "";
                    cmd.Parameters.Add("@ParentId", System.Data.SqlDbType.Int).Value = DBNull.Value;
                    cmd.CommandType = System.Data.CommandType.StoredProcedure;

                    var result = cmd.ExecuteScalar().ToString();

                    if (result == string.Empty)
                    // it's an update
                    {
                        newId = obj.Id;
                    }
                    else
                    // it's an insert
                    {
                        newId = int.Parse(result);
                    }

                    // clean up Milestones that are in database but not present in the inputmodel
                    // do cleaning before storing the new milestone(s) to db, otherwise this / these will be deleted immediately since the newly generated id probably does not match the id passed in the inputmodel
                    var msrep = new MilestoneRepository();
                    // get all existing milestoneid's for this release
                    var currentMilestones = msrep.GetConfiguredMilestonesForRelease(newId).Select(m => m.Id).ToList();
                    // get all milestoneId's contained in the inputmodel
                    var newMilestones = obj.Milestones.Select(m => m.Id).ToList();
                    // remove all new id's from existing id's, keeping all obsolete id's. 'RemoveAll' returns the amount removed, the collection itself is changed
                    var amountObsolete = currentMilestones.RemoveAll(ms => newMilestones.Contains(ms));
                    foreach (var obsoleteId in currentMilestones)
                    {
                        this.DeleteMilestone(obsoleteId);
                    }

                    foreach (var phase in obj.Phases)
                    {
                        this.SavePhaseConfiguration(phase, newId);
                    }

                    foreach (var milestone in obj.Milestones)
                    {
                        this.SaveMilestoneConfiguration(milestone, newId);
                    }

                    // Projects are not value objects, they can be tracked and maintained seperately.
                    // They do however belong to the Release aggregate but they need to be assigned / unassigned, not just deleted and inserted

                    var projRep = new ProjectRepository();
                    // get all existing projectid's for this release
                    var currentProjects = projRep.GetConfiguredProjectsForRelease(newId).Select(m => m.Id).ToList();
                    // create copy to determine obsolete projects
                    var obsoleteProjects = new List<int>();
                    obsoleteProjects.AddRange(currentProjects);

                    // remove all configured id's in inputmodel from existing id's, keeping all obsolete id's. 'RemoveAll' returns the amount removed, the collection itself is changed
                    var amountObsoleteProjects = obsoleteProjects.RemoveAll(p => obj.Projects.Contains(p));
                    foreach (var obsoleteId in obsoleteProjects)
                    {
                        this.UnAssignProject(newId, obsoleteId);
                    }

                    // remove current projects from configured projects in inputmodel, leaving all new projects
                    obj.Projects.RemoveAll(p => currentProjects.Contains(p));

                    // completely renew the Projects for the Release as set in the client app
                    //var cmdDelCross = new SqlCommand(string.Format("Delete from ReleaseProjects where PhaseId = {0}", newId), conn);
                    //cmdDelCross.ExecuteNonQuery();

                    if (obj.Projects != null && obj.Projects.Count > 0)
                    {
                        var cmdInsertReleaseProject = new SqlCommand("sp_insert_releaseproject", conn);
                        cmdInsertReleaseProject.Parameters.Add("@ReleaseId", System.Data.SqlDbType.Int).Value = newId;
                        cmdInsertReleaseProject.Parameters.Add("@ProjectId", System.Data.SqlDbType.Int).Value = 0;
                        cmdInsertReleaseProject.CommandType = System.Data.CommandType.StoredProcedure;

                        foreach (var projId in obj.Projects)
                        {
                            cmdInsertReleaseProject.Parameters["@ProjectId"].Value = projId;
                            cmdInsertReleaseProject.ExecuteNonQuery();
                        }
                    }
                }

                var rel = this.GetReleaseSummary(newId);
                this.GenerateStatusRecords(rel);

                return rel;
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Esempio n. 24
0
        public ReleaseModels.Milestone SaveMilestone(MilestoneInputModel obj)
        {
            var conn = new SqlConnection("Data Source=localhost\\SQLENTERPRISE;Initial Catalog=Planner;Integrated Security=SSPI;MultipleActiveResultSets=true");
            int milestoneId = 0;
            try
            {
                using (conn)
                {
                    conn.Open();

                    var cmd = new SqlCommand("sp_upsert_milestone", conn);
                    cmd.Parameters.Add("@Id", System.Data.SqlDbType.Int).Value = obj.Id;
                    cmd.Parameters.Add("@Title", System.Data.SqlDbType.VarChar).Value = obj.Title;
                    cmd.Parameters.Add("@Description", System.Data.SqlDbType.VarChar).Value = obj.Description ?? "";
                    cmd.Parameters.Add("@Date", System.Data.SqlDbType.VarChar).Value = obj.Date.ToDateTimeFromDutchString();
                    cmd.Parameters.Add("@Time", System.Data.SqlDbType.VarChar).Value = obj.Time ?? "";
                    cmd.Parameters.Add("@PhaseId", System.Data.SqlDbType.Int).Value = obj.PhaseId;
                    cmd.CommandType = System.Data.CommandType.StoredProcedure;

                    var result = cmd.ExecuteScalar();
                    var newId = result == null ? 0 : int.Parse(result.ToString());

                    // it's an update (case 1) or an insert (case 2)
                    milestoneId = newId == 0 ? obj.Id : newId;

                    // completely renew the Deliverables for the Milestone as set in the client app
                    var cmdDelCross = new SqlCommand(string.Format("Delete from MilestoneDeliverables where MilestoneId = {0}", milestoneId), conn);
                    cmdDelCross.ExecuteNonQuery();

                    if (obj.Deliverables != null && obj.Deliverables.Count > 0)
                    {
                        var cmdInserMilestoneDeliverable = new SqlCommand("sp_insert_milestonedeliverable", conn);
                        cmdInserMilestoneDeliverable.Parameters.Add("@MilestoneId", System.Data.SqlDbType.Int).Value = milestoneId;
                        cmdInserMilestoneDeliverable.Parameters.Add("@DeliverableId", System.Data.SqlDbType.Int).Value = 0;
                        /*cmdInserMilestoneDeliverable.Parameters.Add("@HoursRemaining", System.Data.SqlDbType.Int).Value = 0;
                        cmdInserMilestoneDeliverable.Parameters.Add("@InitialEstimate", System.Data.SqlDbType.Int).Value = 0;
                        cmdInserMilestoneDeliverable.Parameters.Add("@Owner", System.Data.SqlDbType.VarChar).Value = string.Empty;
                        cmdInserMilestoneDeliverable.Parameters.Add("@State", System.Data.SqlDbType.VarChar).Value = string.Empty;*/
                        cmdInserMilestoneDeliverable.CommandType = System.Data.CommandType.StoredProcedure;

                        foreach (var itm in obj.Deliverables)
                        {
                            cmdInserMilestoneDeliverable.Parameters["@DeliverableId"].Value = itm.Id;
                            /*cmdInserMilestoneDeliverable.Parameters["@HoursRemaining"].Value = itm.HoursRemaining;
                            cmdInserMilestoneDeliverable.Parameters["@InitialEstimate"].Value = itm.InitialHoursEstimate;
                            cmdInserMilestoneDeliverable.Parameters["@Owner"].Value = itm.Owner ?? "";
                            cmdInserMilestoneDeliverable.Parameters["@State"].Value = itm.State ?? "";*/

                            cmdInserMilestoneDeliverable.ExecuteNonQuery();
                        }
                    }

                }

                var rel = this.GetReleaseSummary(obj.PhaseId);
                this.GenerateStatusRecords(rel);
                var msrep = new MilestoneRepository();
                var milestone = msrep.GetItemById(milestoneId);
                return milestone;

            }
            catch (Exception ex)
            {
                throw;
            }
        }
Esempio n. 25
0
        public JsonResult GetReleaseProgress(int phaseid, int milestoneId)
        {
            // get complete progress data per artefact
            var rep = new ReleaseRepository();
            var progress = rep.GetArtefactsProgress(phaseid, milestoneId);

            // get burndown for total
            var msRep = new MilestoneRepository();
            var ms = msRep.GetItemById(milestoneId);

            try
            {
                // TODO: determine startdate by using the Phase startdate to which the Milestone is connected
                var uc = new GetBurndownData(new Milestone { Id = milestoneId, Date = ms.Date, Release = new Release { Id = phaseid } }, DateTime.Now.AddDays(-40));
                var burndown = uc.Execute();

                return this.Json(new { Progress = progress, Burndown = burndown }, JsonRequestBehavior.AllowGet);
            }
            catch (ConditionNotMetException ex)
            {
                HttpContext.Response.StatusDescription = string.Format("A condition has not been met: {0}", ex.Message);
                HttpContext.Response.StatusCode = 400;
                return this.Json(string.Format("A condition has not been met: {0}", ex.Message), JsonRequestBehavior.AllowGet);
            }
            catch (ProcessException ex)
            {
                HttpContext.Response.StatusDescription = string.Format("A use case processing exception has occurred: {0}", ex.Message);
                HttpContext.Response.StatusCode = 400;
                return this.Json(string.Format("A use case processing exception has occurred: {0}", ex.Message), JsonRequestBehavior.AllowGet);
            }
            catch (Exception ex)
            {
                HttpContext.Response.StatusDescription = string.Format("An exception has occurred: {0}", ex.Message);
                HttpContext.Response.StatusCode = 500;
                return this.Json(string.Format("An exception has occurred: {0}", ex.Message), JsonRequestBehavior.AllowGet);
            }
        }