Ejemplo n.º 1
0
        /// <summary>
        /// Edit family.
        /// </summary>
        /// <param name="editor">
        /// The editor.
        /// </param>
        /// <returns>
        /// The <see cref="FamilyEditor"/>.
        /// </returns>
        public bool EditFamily(FamilyEditor editor)
        {
            bool success;

            switch (editor.State)
            {
            case ObjectStatus.ObjectState.Update:
                success = this.UpdateDatabaseFamily(editor);
                break;

            case ObjectStatus.ObjectState.Delete:
                success = this.DeleteDatabaseFamily(editor);
                break;

            case ObjectStatus.ObjectState.Create:
                success = this.CreateDatabaseFamily(editor);
                break;

            default:
                success = true;
                break;
            }

            return(success);
        }
        public void MyTestInitialize()
        {
            familyList = new List <FamilyEditor>
            {
                new FamilyEditor {
                    Id = 3, Name = "Name", Description = "Description"
                },
                new FamilyEditor {
                    Name = "Name", Description = "Description", Active = true, State = ObjectStatus.ObjectState.Update
                },
            };

            familyCreate = new FamilyEditor {
                Name = "Name", Description = "Description", Active = false, State = ObjectStatus.ObjectState.Create
            };
            familyUpdate = new FamilyEditor {
                Name = "Name", Description = "Description", Active = true, State = ObjectStatus.ObjectState.Update
            };
            familyDelete = new FamilyEditor {
                Name = "Name", Description = "Description", Active = true, State = ObjectStatus.ObjectState.Delete
            };
            familyDeactiv = new FamilyEditor {
                Name = "Name", Description = "Description", Active = false, State = ObjectStatus.ObjectState.Update
            };
            familyActiv = new FamilyEditor {
                Name = "Name", Description = "Description", Active = true, State = ObjectStatus.ObjectState.Update
            };
            familyRead = new FamilyEditor {
                Name = "Name", Description = "Description", Active = true
            };
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Update database family.
        /// </summary>
        /// <param name="editor">
        /// The editor.
        /// </param>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        public bool UpdateDatabaseFamily(FamilyEditor editor)
        {
            var editedFamily = this.CreateADatabaseFamily(editor);

            var success = this.familyRepo.UpdateFamily(editedFamily);

            return(success && this.familyRepo.UpdateFamilyServices(editor.Id, editor.CategoryIds));
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Try to scroll to the top of the list on filter text change
 /// Don't use autoscroll option in xaml as this disables the
 /// virtual list slowing the program significantly.
 /// </summary>
 private void scrollToTop()
 {
     try
     {
         FamilyEditor.ScrollIntoView(FamilyEditor.Items[0]);
     }
     catch { }
 }
Ejemplo n.º 5
0
        /// <summary>
        /// GET: FamilyEditor/Create
        /// </summary>
        public ActionResult Create()
        {
            this.SetupViewBag();
            //Inactive family by default, renders empty list of checkboxes
            FamilyEditor famEditor = new FamilyEditor {
                Active = false, CategoryIds = new List <int>()
            };

            return(this.View(famEditor));
        }
Ejemplo n.º 6
0
        /// <summary>
        /// The filter text changed, update the list based on the new filter.
        /// </summary>
        private void FilterTextBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            FamilyEditor.FilterList(FilterTextBox.Text);
            if (FamilyEditor.Items.Count > 0)
            {
                FamilyEditor.ScrollIntoView(FamilyEditor.Items[0]);
            }

            UpdateControls(FilterTextBox.Text);
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Create a database family.
 /// </summary>
 /// <param name="editor">
 /// The editor.
 /// </param>
 /// <returns>
 /// The <see cref="Family"/>.
 /// </returns>
 private Family CreateADatabaseFamily(FamilyEditor editor)
 {
     return(new Family
     {
         Active = editor.Active,
         Description = editor.Description,
         ID = editor.Id,
         Name = editor.Name,
         SpecialPopulation = editor.IsSpecialPopulation
     });
 }
        public void DeleteHelperTest()
        {
            FamilyEditorsController controller = new FamilyEditorsController();

            FamilyEditor sampleFamily = new FamilyEditor
            {
                Name        = "Name",
                Description = "Description",
                State       = ObjectStatus.ObjectState.Read //test to see that this is changed to Delete
            };
            var result = controller.DeleteHelper(sampleFamily);

            Assert.IsNotNull(result);
            Assert.AreEqual(familyDelete.State, sampleFamily.State);
        }
Ejemplo n.º 9
0
        public ActionResult Delete(FamilyEditor famEditor)
        {
            try
            {
                famEditor = DeleteHelper(famEditor);

                this.famLogic.EditFamily(famEditor); //Sending the delete command to the FamiliesLogic object

                return(this.RedirectToAction("Index"));
            }
            catch
            {
                Console.WriteLine("Error activating FamilyEditor " + famEditor.Id);
                return(this.View());
            }
        }
        public void ActivateHelperTest()
        {
            FamilyEditorsController controller = new FamilyEditorsController();

            FamilyEditor sampleFamily = new FamilyEditor
            {
                Name        = "Name",
                Description = "Description",
                Active      = false,                        //test to see that this changed to true
                State       = ObjectStatus.ObjectState.Read //test to see that this is changed to Update
            };
            var result = controller.ActivateHelper(sampleFamily);

            Assert.IsNotNull(result);
            Assert.AreEqual(familyActiv.Active, sampleFamily.Active);
            Assert.AreEqual(familyActiv.State, sampleFamily.State);
        }
        public void MyTestInitialize()
        {
            this.target = new FamiliesLogic();

            this.websiteFamily = new FamilyEditor
            {
                Active      = true,
                Description = "Test Family",
                CategoryIds = new List <int> {
                    1, 2
                },
                Id    = 1,
                Name  = "Edit Family",
                State = ObjectStatus.ObjectState.Read
            };

            this.databaseFamily = new Family
            {
                Active      = true,
                Description = "Test database family",
                ID          = 1,
                Name        = "Edit database family",
            };

            this.databaseFamilyServices1 = new FamilyService {
                FamilyID = 1, ID = 1, ServiceID = 1
            };
            this.databaseFamilyServices2 = new FamilyService {
                FamilyID = 1, ID = 2, ServiceID = 2
            };
            this.databaseFamilyServicesList = new List <FamilyService>
            {
                this.databaseFamilyServices1,
                this.databaseFamilyServices2
            };

            this.websiteFamilyList = new List <FamilyEditor> {
                this.websiteFamily
            };

            this.databaseFamilyList = new List <Family> {
                this.databaseFamily
            };
        }
Ejemplo n.º 12
0
        public ActionResult Edit(FamilyEditor famEditor)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var editedFamily = this.EditHelper(famEditor);
                    this.famLogic.EditFamily(editedFamily);

                    return(this.RedirectToAction("Details", new { id = famEditor.Id }));
                }
                this.resetForInvalidModel(famEditor);
                TempData["Error"] = "Entry invalid, please include a category";
                return(View(famEditor));
            }
            catch
            {
                Console.WriteLine("Error updating FamilyEditor " + famEditor.Id);
                return(this.View());
            }
        }
Ejemplo n.º 13
0
        public ActionResult Create(FamilyEditor famEditor)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    famEditor = CreateHelper(famEditor);
                    famLogic.EditFamily(famEditor);

                    return(this.RedirectToAction("Index"));
                }
                this.resetForInvalidModel(famEditor);
                TempData["Error"] = "Entry invalid, please include a category";
                return(View(famEditor));
            }
            catch
            {
                this.resetForInvalidModel(famEditor);
                TempData["Error"] = "Entry invalid, please include a category";
                return(View(famEditor));
            }
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Create database family.
        /// </summary>
        /// <param name="editor">
        /// The editor.
        /// </param>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        public bool CreateDatabaseFamily(FamilyEditor editor)
        {
            var family = new Family
            {
                Active            = editor.Active,
                Description       = editor.Description,
                Name              = editor.Name,
                SpecialPopulation = editor.IsSpecialPopulation
            };

            var newFamily = this.familyRepo.CreateFamily(family);

            if (newFamily == null)
            {
                return(false);
            }

            foreach (var categoryId in editor.CategoryIds)
            {
                var created = this.CreateFamilyService(newFamily.ID, categoryId);
            }

            return(true);
        }
Ejemplo n.º 15
0
 /// <summary>
 /// The filter text changed, update the list based on the new filter.
 /// </summary>
 private void FilterTextBox_TextChanged(object sender, TextChangedEventArgs e)
 {
     FamilyEditor.FilterList(FilterTextBox.Text);
 }
Ejemplo n.º 16
0
        /// <summary>
        /// Delete database family.
        /// </summary>
        /// <param name="editor">
        /// The editor.
        /// </param>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        public bool DeleteDatabaseFamily(FamilyEditor editor)
        {
            var success = this.familyRepo.DeleteFamilyServices(editor.Id);

            return(this.familyRepo.DeleteFamily(this.familyRepo.GetFamilyById(editor.Id)));
        }
Ejemplo n.º 17
0
 private void resetForInvalidModel(FamilyEditor famEditor)
 {
     this.SetupViewBag();
     famEditor.CategoryIds = new List <int>();
 }
Ejemplo n.º 18
0
 /// <summary>
 /// Sets the familyEditor state to Delete
 /// </summary>
 /// <param name="familyEditor">Family editor to delete</param>
 /// <returns>familyEditor with an updated State</returns>
 public FamilyEditor DeleteHelper(FamilyEditor familyEditor)
 {
     familyEditor.State = ObjectStatus.ObjectState.Delete; //Set the object's state to Update
     return(familyEditor);
 }
Ejemplo n.º 19
0
 /// <summary>
 /// Sets the FamilyEditor famEditor state to Deactivate and updates the Category
 /// </summary>
 /// <param name="famEditor">FamilyEditor to have its state changed</param>
 /// <returns>Returns the FamilyEditor with State set to Activate</returns>
 public FamilyEditor ActivateHelper(FamilyEditor famEditor)
 {
     famEditor.State  = ObjectStatus.ObjectState.Update;
     famEditor.Active = true;
     return(famEditor);
 }