/// <summary> /// Get a LibraryBookStatus by it's id /// </summary> /// <param name="libraryBookStatusCode"></param> /// <returns>The <see cref="LibraryBookStatusApiModel"/> </returns> public LibraryBookStatusApiModel GetLibraryBookStatusByLibraryBookStatusCode(string libraryBookStatusCode) { var parameters = new { libraryBookStatusCode }; LibraryBookStatusApiModel libraryBookStatusApiModel = null; using (var connection = this.OpenConnection()) { libraryBookStatusApiModel = connection.Query <LibraryBookStatusApiModel, LibraryBookApiModel, LibraryUserApiModel, LibraryBookStatusApiModel>( @"SELECT C.LibraryBookStatusCode, C.DateCheckedOut, C.DateReturned, C.DateCreated, C.CreatedBy, C.DateModified, C.ModifiedBy, LB.LibraryBookCode, LB.ISBN, LB.Title, LB.Author, LB.IsStolen, LB.IsLost, LB.CopyNumber, LB.DateCreated, LB.CreatedBy, LB.DateModified, LB.ModifiedBy, LU.LibraryUserCode, LU.Title, LU.Name, LU.PhoneNumber, LU.MobilePhoneNumber, LU.Email, LU.AlternativePhoneNumber, LU.AlternativeEmail, LU.AddressLine1, LU.AddressLine2, LU.AddressLine3, LU.City, LU.County, LU.Country, LU.Postcode, LU.GDPRInformedDate,LU.GDPRInformedBy,LU.GDPRHowInformed,LU.GDPRNotes,LU.LibraryUserByPost,LU.LibraryUserByPostConsentDate,LU.LibraryUserByEmail, LU.LibraryUserByEmailConsentDate,LU.LibraryUserByPhone,LU.LibraryUserByPhoneConsentDate,LU.LibraryUserBySMS,LU.LibraryUserBySMSConsentDate, LU.DateCreated, LU.CreatedBy, LU.DateModified, LU.ModifiedBy FROM LibraryBookStatus C INNER JOIN LibraryBook LB ON LB.LibraryBookId = c.LibraryBookId INNER JOIN LibraryUser LU ON LU.LibraryUserId = C.LibraryBookUserId WHERE C.LibraryBookStatusCode = @LibraryBookStatusCode" , (lbs, lb, lu) => { lbs.LibraryBook = lb; lbs.LibraryUser = lu; return(lbs); }, splitOn: "LibraryBookCode,LibraryUserCode", param: parameters, commandType: CommandType.Text).SingleOrDefault(); } return(libraryBookStatusApiModel); }
public IActionResult Insert([FromBody] LibraryBookStatusApiModel model) { int result = 0; var libraryBookStatusCode = ""; if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (model != null) { int?retVal = _libraryBookStatusWebApiManager.GetCountOfBookCurrentLent(model?.LibraryUser.LibraryUserCode); if (retVal != null && retVal.Value > 4) { ModelState.AddModelError(string.Empty, "Maximum number of books exceeded"); return(BadRequest(ModelState)); } LibraryBookApiModel libraryBookApiModel = _libraryBookWebApiManager.GetLibraryBookByLibraryBookCode(model.LibraryBook?.LibraryBookCode); if (libraryBookApiModel == null) { ModelState.AddModelError(string.Empty, "Library book not found"); return(BadRequest(ModelState)); } if (_libraryBookStatusWebApiManager.HasMoreThanOneBookWithSameISBN(libraryBookApiModel.ISBN, model?.LibraryUser.LibraryUserCode)) { ModelState.AddModelError(string.Empty, "Library User already has that book"); return(BadRequest(ModelState)); } model.CreatedBy = GetCurrentUser(); model.DateCreated = DateTime.Now; model.ModifiedBy = GetCurrentUser(); model.DateModified = DateTime.Now; result = _libraryBookStatusWebApiManager.InsertLibraryBookStatus(model, out libraryBookStatusCode); } switch (result) { case 1: return(new ContentResult { Content = libraryBookStatusCode, ContentType = "text/plain", StatusCode = 200 }); default: ModelState.AddModelError(string.Empty, "Failed to insert record"); break; } return(BadRequest(ModelState)); }
public async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Anonymous, "put", Route = "updatelibrarybookstatus")] HttpRequest req, ILogger log) { try { var result = _tokenProvider.ValidateToken(req); if (result.Status == AccessTokenStatus.Valid) { log.LogInformation($"Request received for {result.Principal.Identity.Name}."); } else { return(new UnauthorizedResult()); } string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); LibraryBookStatusApiModel model = JsonConvert.DeserializeObject <LibraryBookStatusApiModel>(requestBody); if (model == null) { return(new BadRequestObjectResult("Please pass LibraryBookApiModel in the request body")); } int retVal = 0; if (model != null) { model.ModifiedBy = _tokenProvider.User; model.DateModified = DateTime.Now; retVal = _libraryBookStatusWebApiManager.UpdateLibraryBookStatus(model); } if (retVal < 1) { return(new BadRequestObjectResult("Failed to insert record")); } return(new OkResult()); } catch (Exception ex) { log.LogError($"Caught exception: {ex.Message}"); return(new BadRequestObjectResult(ex.Message)); } }
/// <summary> /// Updare LibraryBookStatus /// </summary> /// <param name="libraryBookStatus"></param> /// <returns>The<see cref="int"/> </returns> public int UpdateLibraryBookStatus(LibraryBookStatusApiModel libraryBookStatus, TransactionParam transactionParam = null) { var parameters = new DynamicParameters(); parameters.Add(name: "LibraryBookStatusCode", value: libraryBookStatus.LibraryBookStatusCode); parameters.Add(name: "dateCheckedOut", value: libraryBookStatus.DateCheckedOut); parameters.Add(name: "dateReturned", value: libraryBookStatus.DateReturned); parameters.Add(name: "modifiedBy", value: libraryBookStatus.ModifiedBy); parameters.Add(name: "modifiedDate", value: DateTime.Now); const string sql = @"UPDATE LibraryBookStatus SET DateCheckedOut = @dateCheckedOut ,DateReturned = @dateReturned ,ModifiedBy = @modifiedBy ,DateModified = @modifiedDate WHERE LibraryBookStatusCode = @LibraryBookStatusCode" ; libraryBookStatus.DateModified = DateTime.Now; int rowaffected = 0; if (transactionParam != null) { rowaffected = transactionParam.Connection.Execute( sql, param: parameters, commandType: CommandType.Text, transaction: transactionParam.Transaction); } else { using (var connection = this.OpenConnection()) { rowaffected = connection.Execute( sql, param: parameters, commandType: CommandType.Text); } } return(rowaffected); }
public static LibraryBookStatusViewModel CreateLibraryBookStatusViewModel(LibraryBookStatusApiModel apiModel) { return(new LibraryBookStatusViewModel() { LibraryBookStatusCode = apiModel.LibraryBookStatusCode, DateCheckedOut = (apiModel.DateCheckedOut != null) ? apiModel.DateCheckedOut.Value.ToString("yyyy-MM-dd HH:mm:ss") : "", DateReturned = (apiModel.DateReturned != null) ? apiModel.DateReturned.Value.ToString("yyyy-MM-dd HH:mm:ss") : "", StrDateCheckedOut = (apiModel.DateCheckedOut != null) ? apiModel.DateCheckedOut.Value.ToString("yyyy-MM-dd HH:mm:ss") : "", StrDateReturned = (apiModel.DateReturned != null) ? apiModel.DateReturned.Value.ToString("yyyy-MM-dd HH:mm:ss") : "", CreatedBy = apiModel.CreatedBy, DateCreated = apiModel.DateCreated, ModifiedBy = apiModel.ModifiedBy, DateModified = apiModel.DateModified, LibraryBookCode = apiModel.LibraryBook?.LibraryBookCode, LibraryBookTitle = apiModel.LibraryBook?.Title, LibraryUserCode = apiModel.LibraryUser?.LibraryUserCode, LibraryUserName = apiModel.LibraryUser?.LibraryUserName }); }
public IActionResult Update([FromBody] LibraryBookStatusApiModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } model.ModifiedBy = GetCurrentUser(); var result = _libraryBookStatusWebApiManager.UpdateLibraryBookStatus(model); switch (result) { case 1: return(Ok()); default: ModelState.AddModelError(string.Empty, "Unable to Update book status"); break; } return(BadRequest(ModelState)); }
/// <summary> /// Insert LibraryBookStatus /// </summary> /// <param name="libraryBookStatus"></param> /// <param name="libraryBookStatusCode"></param> /// <returns>The<see cref="int"/> </returns> public virtual int InsertLibraryBookStatus(LibraryBookStatusApiModel libraryBookStatus, out string libraryBookStatusCode, TransactionParam transactionParam = null) { libraryBookStatusCode = _randomKeyGenerator.GetUniqueKey(9); libraryBookStatus.LibraryBookStatusCode = libraryBookStatusCode; var parameters = new DynamicParameters(); parameters.Add(name: "libraryBookStatusCode", value: libraryBookStatusCode); parameters.Add(name: "dateCheckedOut", value: libraryBookStatus.DateCheckedOut); parameters.Add(name: "dateReturned", value: libraryBookStatus.DateReturned); parameters.Add(name: "libraryUserCode", value: libraryBookStatus.LibraryUser.LibraryUserCode); parameters.Add(name: "createdBy", value: libraryBookStatus.CreatedBy); //parameters.Add(name: "dateCreated", value: libraryBookStatus.DateCreated); parameters.Add(name: "modifiedBy", value: libraryBookStatus.ModifiedBy); //parameters.Add(name: "dateModified", value: libraryBookStatus.DateModified); int rowaffected = 0; string sql = @"INSERT INTO LibraryBookStatus ( LibraryBookStatusCode, DateCheckedOut, DateReturned, DateCreated, CreatedBy, DateModified, ModifiedBy, LibraryBookId, LibraryBookUserId ) SELECT @libraryBookStatusCode, @dateCheckedOut, @dateReturned, NOW(), @createdBy, NOW(), @modifiedBy, @libraryBookId, LU.LibraryUserId FROM LibraryUser LU WHERE LU.LibraryUserCode = @libraryUserCode"; if (transactionParam != null) { int bookId = transactionParam.Connection.Query <int>(@"SELECT LibraryBookId FROM LibraryBook WHERE LibraryBookCode = @libraryBookCode", new { libraryBookStatus.LibraryBook.LibraryBookCode } ).SingleOrDefault(); parameters.Add(name: "@libraryBookId", value: bookId); rowaffected = transactionParam.Connection.Execute( sql, param: parameters, commandType: CommandType.Text, transaction: transactionParam.Transaction); } else { using (var connection = this.OpenConnection()) { int bookId = connection.Query <int>(@"SELECT LibraryBookId FROM LibraryBook WHERE LibraryBookCode = @libraryBookCode", new { libraryBookStatus.LibraryBook.LibraryBookCode } ).SingleOrDefault(); parameters.Add(name: "@libraryBookId", value: bookId); rowaffected = connection.Execute( sql, param: parameters, commandType: CommandType.Text); } } return(rowaffected); }
public async Task <BoolResponse> Update(LibraryBookStatusApiModel apiModel) { var createBranchResponse = await PutEncodedContentWithSimpleBoolResponse <BoolResponse, LibraryBookStatusApiModel>(_apiUrl /*+ APIConstants.Update*/, apiModel); return(createBranchResponse); }
public async Task <IntResponse> Insert(LibraryBookStatusApiModel apiModel) { var createBranchResponse = await PostEncodedContentWithSimpleResponse <IntResponse, LibraryBookStatusApiModel>(_apiUrl /*+ APIConstants.Insert*/, apiModel); return(createBranchResponse); }
/// <summary> /// Updare LibraryBookStatus /// </summary> /// <param name="libraryBookStatus"></param> /// <returns>The<see cref="int"/> </returns> public int UpdateLibraryBookStatus(LibraryBookStatusApiModel libraryBookStatus, TransactionParam transactionParam = null) { return(_libraryBookStatusRepository.UpdateLibraryBookStatus(libraryBookStatus, transactionParam)); }
/// <summary> /// Insert LibraryBookStatus /// </summary> /// <param name="libraryBookStatus"></param> /// <param name="libraryBookStatusCode"></param> /// <returns>The<see cref="int"/> </returns> public int InsertLibraryBookStatus(LibraryBookStatusApiModel libraryBookStatus, out string libraryBookStatusCode, TransactionParam transactionParam = null) { return(_libraryBookStatusRepository.InsertLibraryBookStatus(libraryBookStatus, out libraryBookStatusCode, transactionParam)); }
public async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "insertlibrarybookstatus")] HttpRequest req, ILogger log) { try { var result = _tokenProvider.ValidateToken(req); if (result.Status == AccessTokenStatus.Valid) { log.LogInformation($"Request received for {result.Principal.Identity.Name}."); } else { return(new UnauthorizedResult()); } string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); LibraryBookStatusApiModel model = JsonConvert.DeserializeObject <LibraryBookStatusApiModel>(requestBody); if (model == null) { return(new BadRequestObjectResult("Please pass LibraryBookApiModel in the request body")); } int retVal = 0; string libraryBookCode = string.Empty; if (model != null) { int?returnVal = _libraryBookStatusWebApiManager.GetCountOfBookCurrentLent(model?.LibraryUser.LibraryUserCode); if (returnVal != null && returnVal.Value > 4) { return(new BadRequestObjectResult("Maximum number of books exceeded")); } LibraryBookApiModel libraryBookApiModel = _libraryBookWebApiManager.GetLibraryBookByLibraryBookCode(model.LibraryBook?.LibraryBookCode); if (libraryBookApiModel == null) { return(new BadRequestObjectResult("Library book not found")); } if (_libraryBookStatusWebApiManager.HasMoreThanOneBookWithSameISBN(libraryBookApiModel.ISBN, model?.LibraryUser.LibraryUserCode)) { return(new BadRequestObjectResult("Library User already has that book")); } model.CreatedBy = _tokenProvider.User; model.DateCreated = DateTime.Now; model.ModifiedBy = _tokenProvider.User; model.DateModified = DateTime.Now; retVal = _libraryBookStatusWebApiManager.InsertLibraryBookStatus(model, out libraryBookCode); } if (retVal < 1) { return(new BadRequestObjectResult("Failed to insert record")); } return((ActionResult) new OkObjectResult(new ContentResult { Content = libraryBookCode, ContentType = "text/plain", StatusCode = 200 })); } catch (Exception ex) { log.LogError($"Caught exception: {ex.Message}"); return(new BadRequestObjectResult(ex.Message)); } }