Пример #1
0
        public ActionResult Create(Company model)
        {
            if (!ModelState.IsValid)
                return View(model);

            Company.CreateCompany(model);
            return RedirectToAction("Index");
        }
Пример #2
0
 public static Company SearchCompany(string companyName)
 {
     using(var db = new ApplicationDbContext())
     {
         Company company = new Company();
         company = db.Companies.Where(x => x.CompanyName==companyName).SingleOrDefault();
         return company;
     }  
 }
Пример #3
0
        //Metode

        public static void CreateCompany(Company company)
        {
            if (company != null)
            {
                using(var db=new ApplicationDbContext())
                {
                    //try
                    //{
                        db.Companies.Add(company);
                        db.SaveChanges();
                    //}
                    //catch(Exception ex) when (ex is DbUpdateException || 
                    //                          ex is DbEntityValidationException || 
                    //                          ex is NotSupportedException || 
                    //                          ex is ObjectDisposedException || 
                    //                          ex is InvalidOperationException)
                    //{
                    //    ErrorHelpers.LogError(ex, ErrorLevel.Error, "Error on write in database");
                    //}                    
                }
            }
        }
Пример #4
0
 //POST: Edit
 public static void EditCompany(Company c)
 {
     using (var db = new ApplicationDbContext())
     {
         //try
         //{
             db.Entry(c).State = EntityState.Modified;
             db.SaveChanges();
         //}
         //catch (Exception ex) when (ex is DbUpdateException ||
         //                            ex is DbEntityValidationException ||
         //                            ex is NotSupportedException ||
         //                            ex is ObjectDisposedException ||
         //                            ex is InvalidOperationException)
         //{
         //    ErrorHelpers.LogError(ex, ErrorLevel.Error, "Error on write in database");
         //}
     }
 }