public IActionResult ValidateName([FromBody] BalingStation model) { if (model == null) { return(NotFound()); } if (General.IsDevelopment) { logger.LogDebug(ModelState.ToJson()); } var existing = repository.GetByName(model.BalingStationName); if (existing == null) { return(Accepted(true)); } if (existing.BalingStationId != model.BalingStationId) { return(UnprocessableEntity(Constants.ErrorMessages.EntityExists("Description"))); } else { return(Accepted(true)); } }
public BalingStation Create(BalingStation model) { model.DateCreated = DateTime.Now; dbContext.BalingStations.Add(model); dbContext.SaveChanges(); return(model); }
public SqlRawParameter GetSqlRawParameter(BalingStation parameters) { if (parameters == null) { return(new SqlRawParameter()); } var sqlQry = new StringBuilder(); sqlQry.AppendLine("SELECT * FROM BalingStations "); var whereClauses = new List <string>(); var sqlParams = new List <SqlParameter>(); if (!parameters.IsActive.IsNull()) { sqlParams.Add(new SqlParameter(nameof(parameters.IsActive).Parametarize(), parameters.IsActive)); whereClauses.Add($"{nameof(parameters.IsActive)} = {nameof(parameters.IsActive).Parametarize()}"); } if (whereClauses.Count > 0) { sqlQry.AppendLine(" WHERE "); sqlQry.AppendLine(String.Join(" AND ", whereClauses.ToArray())); } return(new SqlRawParameter() { SqlParameters = sqlParams, SqlQuery = sqlQry.ToString() }); }
public BalingStation Update(BalingStation model) { var entity = dbContext.BalingStations.Find(model.BalingStationId); if (entity == null) { throw new Exception("Selected Record does not exists."); } var holdingsModifed = entity.WarehouseHoldings != model.WarehouseHoldings; entity.BalingStationNum = model.BalingStationNum; entity.DateModified = DateTime.Now; entity.BalingStationCode = model.BalingStationCode; entity.BalingStationName = model.BalingStationName; entity.Location = model.Location; entity.AreaHead = model.AreaHead; entity.DepartmentManager = model.DepartmentManager; entity.WarehouseHoldings = model.WarehouseHoldings; entity.InsuranceCoverage = model.InsuranceCoverage; entity.Selected = model.Selected; entity.IsActive = model.IsActive; //entity.ServerIPAddress = model.ServerIPAddress; //entity.ServerPort = model.ServerPort; dbContext.BalingStations.Update(entity); dbContext.SaveChanges(); if (holdingsModifed) { CheckAndCreateStockStatusReminder(); } return(entity); }
public IQueryable <BalingStation> Get(BalingStation parameters = null) { var sqlRawParams = GetSqlRawParameter(parameters); if (sqlRawParams.SqlParameters.Count == 0) { return(dbContext.BalingStations.AsNoTracking()); } return(dbContext.BalingStations.FromSqlRaw(sqlRawParams.SqlQuery, sqlRawParams.SqlParameters.ToArray()).AsNoTracking()); }
public bool ValidateName(BalingStation model) { var existing = GetByName(model.BalingStationName); if (existing == null) { return(true); } return(existing.BalingStationId == model.BalingStationId); }
public IActionResult Get([FromQuery] BalingStation parameters = null) { try { var model = repository.Get(parameters); return(Ok(model)); } catch (Exception ex) { logger.LogError(ex.GetExceptionMessages()); return(StatusCode(StatusCodes.Status500InternalServerError, Constants.ErrorMessages.FetchError)); } }
private bool validateEntity(BalingStation model) { var validCode = repository.ValidateCode(model); if (!validCode) { ModelState.AddModelError(nameof(BalingStation.BalingStationCode), Constants.ErrorMessages.EntityExists("Code")); } var validName = repository.ValidateName(model); if (!validName) { ModelState.AddModelError(nameof(BalingStation.BalingStationName), Constants.ErrorMessages.EntityExists("Name")); } return(ModelState.ErrorCount == 0); }
public IActionResult Post([FromBody] BalingStation model) { try { if (!ModelState.IsValid) { return(InvalidModelStateResult()); } if (!validateEntity(model)) { return(InvalidModelStateResult()); } return(Accepted(repository.Create(model))); } catch (Exception ex) { logger.LogError(ex.GetExceptionMessages()); return(StatusCode(StatusCodes.Status500InternalServerError, Constants.ErrorMessages.CreateError)); } }
public IActionResult Put([FromBody] BalingStation model) { try { if (!ModelState.IsValid) { return(InvalidModelStateResult()); } if (!validateEntity(model)) { return(InvalidModelStateResult()); } if (repository.Get().Count(a => a.BalingStationId.Equals(model.BalingStationId)) == 0) { return(NotFound(Constants.ErrorMessages.NotFoundEntity)); } return(Accepted(repository.Update(model))); } catch (Exception ex) { logger.LogError(ex.GetExceptionMessages()); return(StatusCode(StatusCodes.Status500InternalServerError, Constants.ErrorMessages.UpdateError)); } }
public bool Delete(BalingStation model) { dbContext.BalingStations.Remove(model); dbContext.SaveChanges(); return(true); }