/// <summary> /// Adds a test unit to the database. /// </summary> /// <param name="unitID">The ID of the unit to update. Should not be provided if adding a new helpdesk.</param> /// <param name="helpdeskID">The ID of the helpdesk that the unit is being added to.</param> /// <param name="name">Name of the unit (auto-generates if not provided, or empty string is provided).</param> /// <param name="code">Code of the unit (auto-generates if not provided, or empty string is provided).</param> /// <param name="isDeleted">Whether or not the helpdesk is removed from the system.</param> /// <param name="topics">A list of topics associated with the unit.</param> /// <returns></returns> public TestDataUnit AddUpdateUnit(int unitID = 0, int?helpdeskID = null, string name = "", string code = "", bool?isDeleted = false, List <string> topics = null) { var request = new AddUpdateUnitRequest(); if (helpdeskID != null) { request.HelpdeskID = (int)helpdeskID; } if (name != null) { if (name == "" && PopulateEmptyStrings) { request.Name = AlphaNumericStringGenerator.GetString(10); } else { request.Name = name; } } if (code != null) { if (code == "" && PopulateEmptyStrings) { request.Code = AlphaNumericStringGenerator.GetString(8); } else { request.Code = code; } } if (isDeleted != null) { request.IsDeleted = (bool)isDeleted; } if (topics != null) { request.Topics = topics; } var facade = new UnitsFacade(); var response = facade.AddOrUpdateUnit(unitID, request); TestDataUnit data = new TestDataUnit(request, response); return(data); }
public IActionResult AddOrUpdateUnit([FromRoute] int id, [FromBody] AddUpdateUnitRequest request) { if (request == null) { return(BadRequest()); } if (!IsAuthorized()) { return(Unauthorized()); } try { var facade = new UnitsFacade(); var response = facade.AddOrUpdateUnit(id, request); switch (response.Status) { case HttpStatusCode.OK: return(Ok(response)); case HttpStatusCode.BadRequest: return(BadRequest(BuildBadRequestMessage(response))); case HttpStatusCode.NotFound: return(NotFound()); case HttpStatusCode.InternalServerError: return(StatusCode(StatusCodes.Status500InternalServerError)); } s_logger.Fatal("This code should be unreachable, unknown result has occured."); } catch (Exception ex) { s_logger.Error(ex, "Unable to add or update unit."); } return(StatusCode(StatusCodes.Status500InternalServerError)); }