private void UpdateExistingProviderType(ProviderTypeVM model) { using (var conn = new SqlConnection(this.connectionString)) using (var cmd = new SqlCommand()) { cmd.Connection = conn; cmd.CommandText = "UPDATE dbo.ProviderTypes SET " + " ProviderTypeCode = @Code, ProviderTypeName = @Name, " + " ProviderTypeIsOutsourced = @Outsourced, ProviderTypeCanSuperviseCase = @CanSupervise " + "WHERE ID = @ID;"; cmd.Parameters.AddWithValue("@ID", model.ID.Value); cmd.Parameters.AddWithValue("@Code", model.Code); cmd.Parameters.AddWithValue("@Name", model.Name); cmd.Parameters.AddWithValue("@Outsourced", model.IsOutsourced); cmd.Parameters.AddWithValue("@CanSupervise", model.CanSuperviseCase); try { cmd.ExecuteNonQueryToInt(); } catch (Exception e) { Exceptions.Handle(e); throw new DataException(e.Message, e); } } }
private void SaveNewProviderType(ProviderTypeVM model) { using (var conn = new SqlConnection(this.connectionString)) using (var cmd = new SqlCommand()) { cmd.Connection = conn; cmd.CommandText = "INSERT INTO dbo.ProviderTypes (ProviderTypeCode, ProviderTypeName, ProviderTypeIsOutsourced, ProviderTypeCanSuperviseCase) VALUES (" + " @Code, @Name, @IsOutsourced, @CanSupervise);"; cmd.Parameters.AddWithValue("@Code", model.Code); cmd.Parameters.AddWithValue("@Name", model.Name); cmd.Parameters.AddWithValue("@IsOutsourced", model.IsOutsourced); cmd.Parameters.AddWithValue("@CanSupervise", model.CanSuperviseCase); try { int?i = cmd.InsertToIdentity(); if (i.HasValue) { model.ID = i.Value; } return; } catch (Exception e) { Exceptions.Handle(e); throw new DataException(e.Message, e); } } }
public void SaveProviderType(ProviderTypeVM providerType) { if (providerType.ID.HasValue) { UpdateExistingProviderType(providerType); } else { SaveNewProviderType(providerType); } }
public ActionResult TypeEdit(ProviderTypeVM model) { return(SaveAction(model, model.ViewHelper, "TypeSearch", "TypeEdit", "ErrorPartial", () => ProviderRepository.SaveProviderType(model))); }