public ActionResponse Edit(TestW testW)
        {
            var response = new ActionResponse();

            var test = db.Tests.Single(c => c.Id == testW.Id);
            test.Name = testW.Name;
            test.TestCategoryId = testW.TestCategoryId;
            test.AcredetationLevelId = testW.AcredetationLevelId;
            test.Temperature = testW.Temperature;
            test.UnitName = testW.UnitName;
            test.TypeId = testW.TypeId;
            test.MethodValue = testW.MethodValue;
            //test.TestMethods = testW.TestMethods;

            try
            {
                var toDelete = new List<TestMethod>();
                //1 add all to be deleted that not existing in the new list
                foreach (var item in test.TestMethods)
                {
                    if (!testW.TestMethods.Any(m => m.Method == item.Method))
                    {
                        toDelete.Add(item);
                        //test.TestMethods.Remove(item);
                        //db.TestMethods.Remove(item);
                    }
                }

                //1.5 Remove them
                foreach (var item in toDelete)
                {
                    db.TestMethods.Remove(item);
                }

                //2 now insert all that are new for the list
                foreach (var item in testW.TestMethods)
                {
                    if (!test.TestMethods.Any(m => m.Method == item.Method))
                    {
                        var method = new TestMethod();
                        method.Id = Guid.NewGuid();
                        method.Method = item.Method;

                        test.TestMethods.Add(method);
                    }
                }

                response.IsSuccess = true;
                db.SaveChanges();
            }
            catch (Exception exc)
            {
                Elmah.ErrorSignal.FromCurrentContext().Raise(exc);
                response.IsSuccess = false;
                response.Error = ErrorFactory.MethodInUseError;
            }

            return response;
        }
        public ActionResponse Edit(TestW testW)
        {
            var response = new ActionResponse();

            var test = Db.Tests.Single(c => c.Id == testW.Id);

            test.Name                = testW.Name;
            test.TestCategoryId      = testW.TestCategoryId;
            test.AcredetationLevelId = testW.AcredetationLevelId;
            test.Temperature         = testW.Temperature;
            test.UnitName            = testW.UnitName;
            test.TypeId              = testW.TypeId;
            test.MethodValue         = testW.MethodValue;

            try
            {
                var toDelete = new List <TestMethod>();

                //1 add all to be deleted that not existing in the new list
                foreach (var item in test.TestMethods)
                {
                    if (!testW.TestMethods.Any(m => m.Method == item.Method))
                    {
                        toDelete.Add(item);
                    }
                }

                //1.5 Remove them
                foreach (var item in toDelete)
                {
                    Db.TestMethods.Remove(item);
                }

                //2 now insert all that are new for the list
                foreach (var item in testW.TestMethods)
                {
                    if (!test.TestMethods.Any(m => m.Method == item.Method))
                    {
                        var method = new TestMethod();
                        method.Id     = Guid.NewGuid();
                        method.Method = item.Method;

                        test.TestMethods.Add(method);
                    }
                }

                response.IsSuccess = true;
                Db.SaveChanges();
            }
            catch (Exception exc)
            {
                Elmah.ErrorSignal.FromCurrentContext().Raise(exc);
                response.IsSuccess = false;
                response.Error     = ErrorFactory.MethodInUseError;
            }

            return(response);
        }
        public bool IsTestExisting(TestW test)
        {
            var founded = Db.Tests.FirstOrDefault(x => x.Name.ToLower() == test.Name.ToLower());

            if (founded != null)
            {
                return(true);
            }

            return(false);
        }
        public ActionResult Create(TestW test)
        {
            if (ModelState.IsValid)
            {
                _rep.Add(test);
                return(RedirectToAction("Index"));
            }

            ViewBag.TestCategoryId      = new SelectList(_rep.GetCategories(), "Id", "Name");
            ViewBag.AcredetationLevelId = new SelectList(_rep.GetAcredetationLevels(), "Id", "Level");
            ViewBag.TypeId = new SelectList(_rep.GetTestTypes(), "Id", "Type");

            return(View(test));
        }
        public void Add(TestW testW)
        {
            var test = testW.ToBase();
            test.Id = Guid.NewGuid();

            if (test.TestMethods != null)
            {
                foreach (var method in test.TestMethods)
                {
                    method.Id = Guid.NewGuid();
                }
            }

            db.Tests.Add(test);

            db.SaveChanges();
        }
        public void Add(TestW testW)
        {
            var test = testW.ToBase();

            test.Id = Guid.NewGuid();

            if (test.TestMethods != null)
            {
                foreach (var method in test.TestMethods)
                {
                    method.Id = Guid.NewGuid();
                }
            }

            Db.Tests.Add(test);

            Db.SaveChanges();
        }
        public ActionResult Edit(Guid?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            TestW test = _rep.GetTest(id.Value);

            if (test == null)
            {
                return(HttpNotFound());
            }

            ViewBag.TestCategoryId      = new SelectList(_rep.GetCategories(), "Id", "Name", test.TestCategoryId);
            ViewBag.AcredetationLevelId = new SelectList(_rep.GetAcredetationLevels(), "Id", "Level", test.AcredetationLevelId);
            ViewBag.TypeId = new SelectList(_rep.GetTestTypes(), "Id", "Type", test.TypeId);

            return(View(test));
        }
        public ActionResult Delete(Guid?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            TestW test = _rep.GetTest(id.Value);

            if (test == null)
            {
                return(HttpNotFound());
            }

            if (Request.IsAjaxRequest())
            {
                return(PartialView(test));
            }

            return(View(test));
        }
        public ActionResult Edit(TestW test)
        {
            if (ModelState.IsValid)
            {
                var response = _rep.Edit(test);

                if (response.IsSuccess)
                {
                    return(RedirectToAction("Index"));
                }
                else
                {
                    ModelState.AddModelError("ErrorExists", response.Error.ErrorText);
                }
            }

            ViewBag.TestCategoryId      = new SelectList(_rep.GetCategories(), "Id", "Name", test.TestCategoryId);
            ViewBag.AcredetationLevelId = new SelectList(_rep.GetAcredetationLevels(), "Id", "Level", test.AcredetationLevelId);
            ViewBag.TypeId = new SelectList(_rep.GetTestTypes(), "Id", "Type", test.TypeId);

            return(View(test));
        }
Пример #10
0
        public bool IsTestExisting(TestW test)
        {
            var founded = db.Tests.FirstOrDefault(x => x.Name.ToLower() == test.Name.ToLower());
            if (founded != null)
                return true;

            return false;
        }