Exemplo n.º 1
0
        public TestMethod ToBase()
        {
            var method = new TestMethod();
            method.Id = this.Id;
            method.TestId = this.TestId;
            method.Method = this.Method;

            return method;
        }
        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;
        }
Exemplo n.º 3
0
 public TestMethodW(TestMethod method)
 {
     this.Id = method.Id;
     this.TestId = method.TestId;
     this.Method = method.Method;
 }