public BaseResponse InsertDeparment([FromBody] DeparmentsRequest request) { BaseResponse response = new BaseResponse(); using (TransactionScope scope = new TransactionScope()) { try { if (!BAplication.ValidateAplicationToken(request.ApplicationToken)) { response.Code = "2"; response.Message = Messages.ApplicationTokenNoAutorize; return(response); } string webRoot = _env.ContentRootPath; string rootPath = _appSettings.Value.rootPath; string ProjectPath = _appSettings.Value.ProjectPath; BaseRequest baseRequest = new BaseRequest(); foreach (MDeparment model in request.Deparments) { MDeparment Deparment = new MDeparment(); Deparment.DeparmentCode = model.DeparmentCode; Deparment.Description = model.Description; Deparment.PracticeArea = model.PracticeArea; Deparment.Region = model.Region; BDeparment.Insert(Deparment); } scope.Complete(); response.Code = "0"; response.Message = "Success"; } catch (Exception ex) { response.Code = "2"; response.Message = ex.Message; scope.Dispose(); } } return(response); }
public static int Insert(MDeparment ent) { using (SqlConnection con = new SqlConnection(ConnectionDB.GetConnectionString())) { SqlCommand cmd = new SqlCommand("sp_Deparment_Ins", con); cmd.CommandTimeout = 0; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@IDeparmentCode", SqlDbType.VarChar).Value = ent.DeparmentCode; cmd.Parameters.Add("@IDescription", SqlDbType.VarChar).Value = ent.Description; cmd.Parameters.Add("@IPracticeArea", SqlDbType.VarChar).Value = ent.PracticeArea; cmd.Parameters.Add("@IRegion", SqlDbType.VarChar).Value = ent.Region; con.Open(); cmd.ExecuteNonQuery(); con.Close(); } return(0); }
public static List <MDeparment> List() { List <MDeparment> lisQuery = new List <MDeparment>(); using (SqlConnection con = new SqlConnection(ConnectionDB.GetConnectionString())) { try { SqlCommand cmd = new SqlCommand("sp_Deparment_Lis", con); cmd.CommandTimeout = 0; cmd.CommandType = CommandType.StoredProcedure; con.Open(); using (var reader = cmd.ExecuteReader()) { while (reader.Read()) { MDeparment entRow = new MDeparment(); entRow.DeparmentId = Convert.ToInt32(reader["DeparmentId"]); entRow.DeparmentCode = Convert.ToString(reader["DeparmentCode"]); entRow.Description = Convert.ToString(reader["Description"]); entRow.PracticeArea = Convert.ToString(reader["PracticeArea"]); lisQuery.Add(entRow); } } con.Close(); } catch (Exception ex) { lisQuery = null; } } return(lisQuery); }
public static int Insert(MDeparment ent) { return(DADeparment.Insert(ent)); }