private void Add_Button_Click(object sender, EventArgs e) { if (String.IsNullOrWhiteSpace(Type_TextBox.Text) || String.IsNullOrWhiteSpace(CodeOfType_TextBox.Text)) { Alert.DisplayError("Invalid input!"); return; } try { if (!mode) { Act_dict type = new Act_dict(); type.act_name = Type_TextBox.Text; type.act_type = CodeOfType_TextBox.Text; ManagerService.NewActType(type); this.Close(); this.Dispose(); } else { Object_type type = new Object_type(); type.name_type = Type_TextBox.Text; type.code_type = CodeOfType_TextBox.Text; ManagerService.NewObjectType(type); this.Close(); this.Dispose(); } } catch (ServiceException exc) { Alert.DisplayError(exc.Message); } }
public static void NewActType(Act_dict type) { try { CarWorkshopModelContext dc = new CarWorkshopModelContext(); var res = (from el in dc.Act_dict where (el.act_name == type.act_name) || (el.act_type == type.act_type) select el).SingleOrDefault(); if (res == null) { dc.Act_dict.Add(type); dc.SaveChanges(); return; } throw new ServiceException("Type already exists!"); } catch (System.Data.Entity.Core.EntityException e) { throw new ServiceException("Database connection error!"); } }