public int Update(int id, SemesterEditModel semester) { var affectedRows = 0; using (var connection = this.Context.Connection) { var statement = $"UPDATE {semesterTableName} SET Name = @Name, StartDate = @StartDate, EndDate = @EndDate WHERE Id = {id}"; var command = new MySqlCommand(statement, connection); command.Parameters.AddWithValue("Name", semester.Name); command.Parameters.AddWithValue("StartDate", semester.StartDate); command.Parameters.AddWithValue("EndDate", semester.EndDate); try { connection.Open(); affectedRows = command.ExecuteNonQuery(); } catch (Exception ex) { this.Log(this.GetExceptionText(ex)); } } return(affectedRows); }
public IActionResult Put(int id, [FromBody] SemesterEditModel model) { if (!this.Validator.ValidateObject(model) || !this.Validator.ValidateRequiredStringProperty(model.Name) || !this.Validator.ValidateDates(model.StartDate, model.EndDate)) { return(BadRequest(new { message = "Bad parameters passed!" })); } var affectedRows = this.semesterService.Edit(id, model); return(this.BuildNonQueryResponse(affectedRows)); }
public int Edit(int id, SemesterEditModel model) { var affectedRows = this.repository.Update(id, model); return(affectedRows); }