Example #1
0
        public async Task <IActionResult> UpdateAProject([FromBody] ProjectProfile projectProfile, string projectNumber)
        {
            if (projectProfile == null)
            {
                var error = new BadRequestException("The given project profile is null / Request Body cannot be read");
                return(StatusCode(StatusCodes.Status400BadRequest, new CustomException <BadRequestException>(error).GetException()));
            }

            if (
                projectProfile.ProjectManager == null || String.IsNullOrEmpty(projectProfile.ProjectManager.UserID) ||
                projectProfile.ProjectSummary == null ||
                String.IsNullOrEmpty(projectProfile.ProjectSummary.ProjectNumber) || String.IsNullOrEmpty(projectNumber) ||
                projectProfile.ProjectSummary.Location == null
                )
            {
                var error = new BadRequestException("The Project (Manager(ID) / Summary / Number / Location) cannot be null or empty string!");
                return(StatusCode(StatusCodes.Status400BadRequest, new CustomException <BadRequestException>(error).GetException()));
            }

            if (projectProfile.ProjectSummary.ProjectNumber != projectNumber)
            {
                var errMessage = $"The project number on URL '{projectNumber}'" +
                                 $" does not match with '{projectProfile.ProjectSummary.ProjectNumber}' in Request Body's Project Summary";
                var error = new BadRequestException(errMessage);
                return(StatusCode(StatusCodes.Status400BadRequest, new CustomException <BadRequestException>(error).GetException()));
            }

            try
            {
                var location = await locationsRepository.GetALocation(projectProfile.ProjectSummary.Location.City);

                var updatedProjectNumber = await projectsRepository.UpdateAProject(projectProfile, location.Id);

                var response = new UpdatedResponse <string>(updatedProjectNumber, "Successfully updated");
                return(StatusCode(StatusCodes.Status200OK, response));
            }
            catch (Exception err)
            {
                if (err is CustomException <InternalServerException> )
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError, ((CustomException <InternalServerException>)err).GetException()));
                }
                else
                {
                    var errMessage = $"Source: {err.Source}\n  Message: {err.Message}\n  StackTrace: {err.StackTrace}\n";
                    if (err is SqlException)
                    {
                        var error = new InternalServerException(errMessage);
                        return(StatusCode(StatusCodes.Status500InternalServerError, new CustomException <InternalServerException>(error).GetException()));
                    }
                    else
                    {
                        var error = new BadRequestException(errMessage);
                        return(StatusCode(StatusCodes.Status400BadRequest, new CustomException <BadRequestException>(error).GetException()));
                    }
                }
            }
        }
 public void TestUpdatedResponse()
 {
     UpdatedResponse response = new UpdatedResponse();
      string contents = "/1 :pserver:abougie@gb-aix-q:2401/usr/local/cvsroot/sandbox AB4%o=wSobI4w\n";
      IList<string> lines = new List<string> { "mod1/", "/usr/local/cvsroot/sandbox/mod1/file1.cs", "/file1.cs/1.2.3.4///", "u=rw,g=rw,o=rw", "74" };
      ResponseTest(response, ResponseType.Updated, 5, "/usr/local/cvsroot/sandbox/mod1/file1.cs", lines, contents);
 }
 public void TestFileResponseBaseProcessMultipleDirectories()
 {
     UpdatedResponse response = new UpdatedResponse();
      IList<string> lines = new List<string> { "mod1/mod2/mod3/", "/usr/local/cvsroot/sandbox/mod1/mod2/mod3/file1.cs", "/file1.cs/1.2.3.4///", "u=rw,g=rw,o=rw", "74" };
      response.Initialize(lines);
      response.Process();
      Assert.AreEqual("mod1/mod2/mod3/", response.Module);
      Assert.AreEqual("/file1.cs/1.2.3.4///", response.EntryLine);
      Assert.AreEqual("/usr/local/cvsroot/sandbox/mod1/mod2/mod3/file1.cs", response.RepositoryPath);
      Assert.AreEqual("file1.cs", response.Name);
      Assert.AreEqual("1.2.3.4", response.Revision);
      Assert.AreEqual("u=rw,g=rw,o=rw", response.Properties);
      Assert.AreEqual(74, response.Length);
      Assert.AreEqual(5, response.LineCount);
 }
 private static UpdatedResponse GetMockUpdatedResponse(string path, string name)
 {
     UpdatedResponse res = new UpdatedResponse();
      IList<string> lines = new List<string>
                           {
                              "Updated " + path,
                              "/usr/local/cvsroot/sandbox/" + path + name,
                              "/" + name + "/1.1.1.1///",
                              "u=rw,g=rw,o=rw",
                              "5"
                           };
      res.Process(lines);
      string text = "abcde";
      res.File.Contents = text.Encode();
      return res;
 }