public long Add(ProcTypeModel model) { //TODO: валидация модели //Сохранение using (var db = new MainDb()) { long id = Convert.ToInt64(db.ProcType.InsertWithIdentity(() => new Kpo.Dal.MainDb.ProcTypeDataModel { Job_Id = model.Job_Id, Name = model.Name })); return(id); } }
private void button2_Click_1(object sender, EventArgs e) { ProcTypeModel pmodel = new ProcTypeModel(); if (0 != proctype.Get_Item("Name", ProcNameText.Text, ConditionType.Equal).Id) { MessageBox.Show("Такая процедура уже существует"); ProcNameText.Clear(); } else { ProcTypeModel model = new ProcTypeModel(); model.Name = ProcNameText.Text; model.Job_Id = job.Get_Item("Name", JobBox.SelectedItem.ToString(), ConditionType.Equal).Id; proctype.Add(model); MessageBox.Show("Запись внесена"); ProcNameText.Clear(); } }
/// <summary> /// Получить элемент по заданным параметрам /// </summary> /// <returns></returns> public ProcTypeModel Get_Item(string field, string value, ConditionType type) { FilterCondition filter = new FilterCondition(field, value, type); using (var db = new MainDb()) { var query = MakeSelect(db); if (filter != null) { if (filter.Field.Equals("Id", StringComparison.CurrentCultureIgnoreCase) && filter.Value != null) { if (filter.Type == ConditionType.Equal) { query = query.Where(q => q.Id.Equals(filter.Value)); } } if (filter.Field.Equals("Name", StringComparison.CurrentCultureIgnoreCase) && filter.Value != null) { if (filter.Type == ConditionType.Equal) { query = query.Where(q => q.Name.Equals(filter.Value)); } } } ProcTypeModel Result = new ProcTypeModel(); try { Result = query.Single(); return(Result); } catch { ProcTypeModel NullResult = new ProcTypeModel(); NullResult.Id = 0; NullResult.Name = "Не определено"; return(NullResult); } } }