Example #1
0
        private ElementResponse AddElementChores(Element element, int year)
        {
            var elementGenericChores = element.ElementGenericChores;

            ElementResponse ElementResponse = new ElementResponse();

            ElementResponse.Chores      = new List <ChoreResponse>();
            ElementResponse.TotalChores = 0;

            List <Chore> AllChoresElement = new List <Chore>();


            foreach (ElementGenericChore elemenGChore in elementGenericChores)
            {
                NewChoresGuideline newChoresGuideline = new NewChoresGuideline();
                newChoresGuideline.GenericChore = elemenGChore.GenericChore;
                newChoresGuideline.ElementId    = element.Id;

                GenericChore gChore       = elemenGChore.GenericChore;
                Period       gChorePeriod = gChore.Period;

                Chore LastChore = GetLastChore(element.Id, gChore.Id, year);

                if (LastChore == null)
                {
                    newChoresGuideline.TimeSpanToAddChores = GetDefaultTimeSpan(year);
                }
                else if (IsTimeSpanIncomplete(LastChore, year) == true)
                {
                    newChoresGuideline.TimeSpanToAddChores = ResumeTimeSpan(LastChore);
                }
                else
                {
                    continue;
                }

                List <Chore> choresAdded = AddingElements(newChoresGuideline);

                AllChoresElement.AddRange(choresAdded);

                ChoreResponse choreResponse = new ChoreResponse();
                choreResponse.TotalChores = choresAdded.Count();
                choreResponse.Period      = newChoresGuideline.GenericChore.Period;

                ElementResponse.Chores.Add(choreResponse);
                ElementResponse.TotalChores += choreResponse.TotalChores;
            }

            InsertChoresToDatabase(AllChoresElement);
            _formatsService.AddFormatValuesToChores(AllChoresElement);

            return(ElementResponse);
        }