public async Task <Cust> Update(Cust entityToUpdate) { using (var conn = Connection) { var sql = "UPDATE Custs " + "SET Name = @Name," + " Address = @Address," + " CityID = @CityID," + "Website = @Website," + " Email = @Email," + "Phone = @Phone," + " Mobile = @Mobile, " + "Fax = @Fax," + "MainIndustryID = @MainIndustryID," + " Industry = @Industry," + "StatusID = @StatusID," + $"Description = @Description Where id = {entityToUpdate.ID}"; conn.Open(); var updeted = await conn.QueryAsync <Cust>(sql, entityToUpdate); var result = GetByID(entityToUpdate.ID); return(result.Result); } }
public async Task <Cust> Save(Cust entity) { Cust ret; if (entity.ID > 0) { ret = Update(entity).Result; } else { ret = Add(entity).Result; } return(ret); }
public async Task <Cust> Add(Cust entity) { using (var conn = Connection) { var sql = "INSERT INTO Custs(Name, Address, CityID,Website,Email,Phone,Mobile,Fax,MainIndustryID,Industry,StatusID,Description) " + "VALUES(@Name, @Address, @CityID, @Website, @Email, @Phone, @Mobile, @Fax, @MainIndustryID, @Industry, @StatusID, @Description);" + "SELECT CAST(SCOPE_IDENTITY() as int) "; conn.Open(); var inseredID = await conn.ExecuteScalarAsync <int>(sql, entity); var result = GetByID(inseredID); return(result.Result); } }