Example #1
0
 public static bool EditCargo(int id, Cargo cargo)
 {
     try
     {
         using (TransportCompanyContext db = new TransportCompanyContext())
         {
             bool           result         = false;
             DataValidation dataValidation = new DataValidation();
             if (dataValidation.CheckAllInput(cargo))
             {
                 var cargos = db.Cargos.ToList();
                 for (int i = 0; i < cargos.Count; i++)
                 {
                     if (cargos[i].Id == id)
                     {
                         cargos[i].CopyFields(cargo);
                         db.SaveChanges();
                         result = true;
                     }
                 }
             }
             return(result);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message.ToString(), ex.Source.ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error);
         return(false);
     }
 }
Example #2
0
        public static bool AddCargo(Cargo cargo)
        {
            try
            {
                DataValidation dataValidation = new DataValidation();

                using (TransportCompanyContext db = new TransportCompanyContext())
                {
                    bool result;
                    if (dataValidation.CheckAllInput(cargo))
                    {
                        db.Cargos.Add(cargo);
                        db.SaveChanges();
                        result = true;
                    }
                    else
                    {
                        result = false;
                    }
                    return(result);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString(), ex.Source.ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
        }