예제 #1
0
        public ActionResult EditModel(computer_brand brand)
        {
            if (brand == null)
            {
                return(RedirectToAction("Index"));
            }

            using (frycz_pcdbEntities entities = new frycz_pcdbEntities())
            {
                computer_brand cb =
                    entities.computer_brand.FirstOrDefault(e => e.idcumputer_brand == brand.idcumputer_brand);
                return(View("EditModel", cb));
            }
        }
예제 #2
0
 public ActionResult SaveAdd(computer_brand brand)
 {
     if (!Validator.validModel(brand))
     {
         ModelState.AddModelError("exist", "Computer model is invalid or inuse.");
         return(View("AddModel", brand));
     }
     using (frycz_pcdbEntities entities = new frycz_pcdbEntities())
     {
         entities.computer_brand.Add(brand);
         Logger.logModel(brand, "Add", User);
         entities.SaveChanges();
         return(RedirectToAction("Index", "ComputerModel"));
     }
 }
예제 #3
0
 public ActionResult Delete(computer_brand brand)
 {
     if (brand == null)
     {
         return(RedirectToAction("Index"));
     }
     using (frycz_pcdbEntities entities = new frycz_pcdbEntities())
     {
         computer_brand b =
             entities.computer_brand.FirstOrDefault(e => e.idcumputer_brand == brand.idcumputer_brand);
         entities.computer_brand.Remove(b);
         Logger.logModel(b, "Delete", User);
         entities.SaveChanges();
         return(RedirectToAction("Index", "ComputerModel"));
     }
 }
예제 #4
0
        public static bool validModel(computer_brand brand)
        {
            if (brand == null)
            {
                return(false);
            }
            if (brand.model == null || brand.model.Equals(String.Empty) || brand.maker == null ||
                brand.maker.Equals(String.Empty))
            {
                return(false);
            }
            using (frycz_pcdbEntities entities = new frycz_pcdbEntities())
            {
                int count = entities.computer_brand.Count(t => t.maker.Equals(brand.maker) && t.model.Equals(brand.model));

                return(count <= 0);
            }
        }
예제 #5
0
 public ActionResult SaveEdit(computer_brand brand)
 {
     if (!Validator.validModel(brand))
     {
         ModelState.AddModelError("exist", "Computer model is invalid or inuse.");
         return(View("EditModel", brand));
     }
     using (frycz_pcdbEntities entities = new frycz_pcdbEntities())
     {
         computer_brand b =
             entities.computer_brand.FirstOrDefault(e => e.idcumputer_brand == brand.idcumputer_brand);
         b.maker = brand.maker;
         b.model = brand.model;
         Logger.logModel(brand, "Edit", User);
         entities.SaveChanges();
         return(RedirectToAction("Index", "ComputerModel"));
     }
 }
예제 #6
0
        public string AddAjax(string model, string maker)
        {
            computer_brand c = new computer_brand();

            c.maker = maker;
            c.model = model;
            if (!Validator.validModel(c))
            {
                return(null);
            }
            using (frycz_pcdbEntities entities = new frycz_pcdbEntities())
            {
                entities.computer_brand.Add(c);
                Logger.logModel(c, "Add", User);
                entities.SaveChanges();

                return("{\"msg\":\"success\"}");
            }
        }
예제 #7
0
 public static void logModel(computer_brand brand, string operationMessage, IPrincipal user)
 {
     logToDB(operationMessage + " computer model: " + brand.maker + " " + brand.model, user);
 }