public ActionResult <OldPart> Get(string id) { try { _logger.LogDebug("Fetching Old Part"); OldPart oldpart = _service.Get(id); if (oldpart != null) { _logger.LogDebug("Old Parts Found. Returning parts found"); return(Ok(oldpart)); } else { _logger.LogDebug("Fetch operation failed. Old part not found"); return(Conflict("Inventory not Found")); } } catch (Exception ex) { //Log error _logger.LogError("An Exception occured: {ex}", ex.Message); _logger.LogError("Stack Trace: {ex}", ex.StackTrace); return(BadRequest(ex)); } }
public async Task <IActionResult> AddInventoryAsync([FromBody] OldPart op) { try { _logger.LogDebug("Inserting a new record"); bool success = await _service.AddAsync(op); if (success) { _logger.LogDebug("Insert Operataion success"); return(Ok("Old part created successfully")); } else { _logger.LogDebug("Insert operation failed. A duplicate Part already exists"); return(Conflict("Duplicate old part found")); } } catch (Exception ex) { //log _logger.LogError("An Exception occured: {ex}", ex.Message); _logger.LogError("Stack Trace: {ex}", ex.StackTrace); return(BadRequest()); } }
public async Task <IActionResult> UpdateInventoryAsync([FromBody] OldPart op) { try { _logger.LogDebug("Updating Old Inventory parts"); bool success = await _service.UpdateAsync(op); if (success) { _logger.LogDebug("Update operation success."); return(Ok("OldPart part updated successfully")); } else { _logger.LogDebug("Update operation failed. Old Part not found"); return(Conflict("OldPart part not found")); } } catch (Exception ex) { //log _logger.LogError("An Exception occured: {ex}", ex.Message); _logger.LogError("Stack Trace: {ex}", ex.StackTrace); return(BadRequest()); } }
public async Task <bool> DeleteAsync(string id) { try { bool saved = false; _logger.LogDebug("Disabling Old Part"); OldPart part = (OldPart)context.OldParts .Where(part => part.Id.Equals(id)).FirstOrDefault(); if (part == null) { _logger.LogDebug("Part not found"); return(false); } _logger.LogDebug("Part found"); part.IsActive = 0; saved = await context.SaveChangesAsync() > 0; if (!saved) { _logger.LogDebug("Disable operation failed"); return(saved); } _logger.LogDebug("Disable operation successful"); return(saved); } catch (Exception ex) { _logger.LogError("An exception occured: {ex}", ex.ToString()); _logger.LogError("Stack Trace: {trace}", ex.StackTrace); return(false); } }
public async Task <bool> AdminDeleteAsync(string id) { try { bool saved = false; _logger.LogDebug("Deleting Old Part"); OldPart part = (OldPart)context.OldParts .Where(part => part.Id.Equals(id)).FirstOrDefault(); if (part == null) { _logger.LogDebug("Delete operation failed. Record not found"); return(false); } _logger.LogDebug("Record found"); context.Remove <OldPart>(part); saved = await context.SaveChangesAsync() > 0; if (!saved) { _logger.LogDebug("Delete operation failed."); } else { _logger.LogDebug("Delete operation success."); } return(saved); } catch (Exception ex) { _logger.LogError("An exception occured: {ex}", ex.ToString()); _logger.LogError("Stack Trace: {trace}", ex.StackTrace); return(false); } }
public async Task <bool> CallUpdateService(OldPart op) { using (var client = GetClient()) { HttpResponseMessage response = await client.PostAsJsonAsync("api/oldparts/update", op); HttpContent result = response.Content; if (response.IsSuccessStatusCode) { return(true); } else { return(false); } } }
public async Task <bool> UpdateAsync(OldPart data) { try { var saved = false; OldPart part = (OldPart)context.OldParts .Where(part => part.Id.Equals(data.Id)).FirstOrDefault(); if (part == null) { _logger.LogDebug("Update operation failed.Part not found"); return(false); } _logger.LogDebug("Part found"); part.Description = data.Description; part.Location = data.Location; part.PartNumber = data.PartNumber; part.Rem = data.Rem; part.DateUpdate = DateTime.Now; saved = await context.SaveChangesAsync() > 0; if (saved) { _logger.LogDebug("Update operation successful"); } else { _logger.LogDebug("Update operation failed"); } return(saved); } catch (Exception ex) { _logger.LogError("An exception occured: {ex}", ex.ToString()); _logger.LogError("Stack Trace: {trace}", ex.StackTrace); return(false); } }
public async Task <bool> AddAsync(OldPart data) { try { _logger.LogDebug("Adding Old part"); bool saved = false; bool isexists = context.Inventories.Any(x => x.PartNumber == data.PartNumber); if (!isexists) { data.DateCreated = DateTime.Now; data.DateUpdate = DateTime.Now; await context.OldParts.AddAsync(data); saved = await context.SaveChangesAsync() > 0; if (saved) { _logger.LogDebug("Insert operation successful"); } else { _logger.LogDebug("Insert operation failed"); } return(saved); } _logger.LogDebug("Insert operation failed. Record already exists"); return(false); } catch (Exception ex) { _logger.LogError("An exception occured: {ex}", ex.ToString()); _logger.LogError("Stack Trace: {trace}", ex.StackTrace); return(false); } }