Exemplo n.º 1
0
        public ActionResult Create(BinderViewModel model)
        {
            if (ModelState.IsValid)
            {
                Binder binder = new Binder
                {
                    BarCode = model.BarCode,
                    CompanyId = model.CompanyId,
                    Description = model.Description,
                    Location = model.Location,
                    Year = model.Year
                };


                int binderId = Binder.CreateBinder(binder);

                if (binderId < 0)
                {
                    BinderTypeBinder.InsertBinderTypeBinder(binderId, model.BinderTypes);
                }

                return RedirectToAction("Details", "Company", new { id= model.CompanyId});
            }

            IEnumerable<Company> companies = Company.GetAllCompany();

            ViewBag.CompanyId = new SelectList(companies, "CompanyId", "CompanyName", model.CompanyId);
            return View(model);
        }
Exemplo n.º 2
0
 public static int CreateBinder(Binder binder)
 {
     if (binder != null)
     {
         using(var db=new ApplicationDbContext())
         {
             //try
             //{
                 db.Binders.Add(binder);
                 db.SaveChanges();
                 return binder.BinderId;
             //}
             //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");
             //}
         }
     }
     return 0;
 }
Exemplo n.º 3
0
        public ActionResult SearchBinder(int companyId, string barCode)
        {
            Binder result = Search.SearchBinder(companyId, barCode);

            Binder binder = new Binder();
            if (result != null)
            {
                binder.BinderId = result.BinderId;
                binder.BarCode = result.BarCode;
                binder.Description = result.Description;
                binder.Year = result.Documents.Count.ToString();
            }
            

            return Json(binder, JsonRequestBehavior.AllowGet);
        }
Exemplo n.º 4
0
 public static void EditBinder(Binder binder)
 {
     if (binder != null)
     {
         using (var db = new ApplicationDbContext())
         {
             //try
             //{
                 db.Entry(binder).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");
             //}
         }
     }
 }
Exemplo n.º 5
0
        public ActionResult Edit(BinderViewModel model)
        {
            if (ModelState.IsValid)
            {
                var binder = new Binder
                {                    
                    BarCode = model.BarCode,
                    Description = model.Description,
                    Location = model.Location,
                    Year = model.Year,
                    BinderId = model.BinderId                    
                };                

                Binder.EditBinder(binder);
                BinderTypeBinder.DeleteBinderTypeBindersById(binder.BinderId);
                BinderTypeBinder.InsertBinderTypeBinder(model.BinderId, model.BinderTypes);

                return RedirectToAction("Details", "Company", new { id = model.CompanyId });
            }

            IEnumerable<Company> companies = Company.GetAllCompany();
            return View(model);
        }