Beispiel #1
0
 public static void AddClient(Client client)
 {
     using (ModelCarServiceContainer context = new ModelCarServiceContainer())
     {
         try
         {
             context.Database.Connection.Open();
             context.ClientSet.Add(client);
             context.SaveChanges();
         }
         catch (DbEntityValidationException ex)
         {
             foreach (DbEntityValidationResult entityErr in ex.EntityValidationErrors)
             {
                 foreach (DbValidationError error in entityErr.ValidationErrors)
                 {
                     throw;
                 }
             }
         }
     }
 }
Beispiel #2
0
        /// <summary>
        /// Add method, adds a new client
        /// </summary>
        /// <param name="fName"></param>
        /// <param name="lName"></param>
        /// <param name="addrs"></param>
        /// <param name="localitate"></param>
        /// <param name="judet"></param>
        /// <param name="tel"></param>
        /// <param name="email"></param>
        public static void Add(string fName, string lName, string addrs, string localitate, string judet, string tel, string email)
        {
            using (ModelCarServiceContainer context = new ModelCarServiceContainer())
            {
                context.Database.Connection.Open();

                try
                {
                    Client client = new Client()
                    {
                        Nume       = fName,
                        Prenume    = lName,
                        Adresa     = addrs,
                        Localitate = localitate,
                        Judet      = judet,
                        Telefon    = tel,
                        Email      = email
                    };

                    context.ClientSet.Add(client);
                    context.SaveChanges();
                }
                catch (DbEntityValidationException ex)
                {
                    foreach (DbEntityValidationResult entityErr in ex.EntityValidationErrors)
                    {
                        foreach (DbValidationError error in entityErr.ValidationErrors)
                        {
                            //Console.WriteLine("Error: {0}", error.ErrorMessage);
                            //return error.ErrorMessage;
                            throw;
                        }
                    }
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Adds a new object of type <see cref="Comanda"/>
        /// </summary>
        /// <param name="autoId"></param>
        /// <param name="clientId"></param>
        /// <param name="stare"></param>
        /// <param name="dataProgramare"></param>
        /// <param name="dataFinalizare"></param>
        /// <param name="kmBord"></param>
        /// <param name="descriere"></param>
        public static void Add(int autoId, int clientId, string stare, DateTime dataProgramare, DateTime dataFinalizare, int kmBord, string descriere)
        {
            using (ModelCarServiceContainer context = new ModelCarServiceContainer())
            {
                context.Database.Connection.Open();

                try
                {
                    Comanda comanda = new Comanda()
                    {
                        AutoId         = autoId,
                        ClientId       = clientId,
                        StareComanda   = stare,
                        DataSystem     = DateTime.Now,
                        DataProgramare = dataProgramare,
                        DataFinalizare = dataFinalizare,
                        KmBord         = kmBord,
                        Descriere      = descriere,
                        ValoarePiese   = 0
                    };

                    context.ComandaSet.Add(comanda);
                    context.SaveChanges();
                }
                catch (DbEntityValidationException ex)
                {
                    foreach (DbEntityValidationResult entityErr in ex.EntityValidationErrors)
                    {
                        foreach (DbValidationError error in entityErr.ValidationErrors)
                        {
                            throw;
                        }
                    }
                }
            }
        }