Ejemplo n.º 1
0
        public IEnumerable <ReportSM> Get()
        {
            //Get Id of current User
            var requestUserId = User.Identity.GetUserId();
            var isAdmin       = User.IsInRole("admin");
            var isAdmin2      = User.IsInRole("846004c4-c444-4ae5-a063-c0401e03bc4f");


            //Get Data From DB
            var query = from r in db.Reports
                        where r.IsDone == false
                        select r;

            var result = query.ToList <Report>();

            List <ReportSM> reports = null;

            if (result != null)
            {
                reports = new List <ReportSM>();

                foreach (var item in result)
                {
                    ReportSM report = new ReportSM();
                    report.ReportId = item.Id;
                    report.FirstNameReportingUser = item.User.FirstName;
                    report.LastNameReportingUser  = item.User.LastName;
                    report.PicId          = item.PhotoId;
                    report.FirstNameOwner = item.Photo.Trip.User.FirstName;
                    report.LastNameOwner  = item.Photo.Trip.User.LastName;
                    report.Comment        = item.Comment;

                    reports.Add(report);
                }
            }

            return(reports);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Generate list of selected flags, separe days too
        /// </summary>
        /// <param name="item"> DataClass object </param>
        /// <param name="flag"> Selected flag for report generation </param>
        /// <returns></returns>
        public static List <FlagOccurrenceClass> GenerateReportSeparateDays(DataClass item, ReportFlag flag)
        {
            List <FlagOccurrenceClass> lis = new List <FlagOccurrenceClass>();
            //  Get tuple based on flag
            var resFromFlag = GetDelegateBasedOnFlag(flag);

            // Assign tuple values returned by method
            Func <Flags, bool> calcuFunc = resFromFlag.Item1;
            string             flagDesc  = resFromFlag.Item2;
            Color currentCol             = resFromFlag.Item3;

            bool     res;                              // result from comparing flags
            DateTime startDate = item.startDate;       // Date to display start of active flags
            bool     endFlag   = false;                // This will signal end of array
            ReportSM state     = ReportSM.STATE_ENTRY; // Inital state of SM

            bool newDay = false;

            for (int i = 0; i < item.data.Length; i++) // Loop thru every 15min value
            {
                if (i + 1 == item.data.Length)
                {
                    endFlag = true;
                }

                Data15MinClass dataItem = item.data[i];      // Get data
                res    = calcuFunc(dataItem.flags);          // Get result from flags compare
                newDay = dataItem.date.Day != startDate.Day; // Get new day indicating flag
                switch (state)
                {
                case ReportSM.STATE_ENTRY:     // Entry state sets startDate and chooses next state
                    startDate = dataItem.date;
                    if (res)
                    {
                        state = ReportSM.STATE_FLAGS_MATCH;
                    }
                    else
                    {
                        state = ReportSM.STATE_FLAGS_DIFFER;
                    }
                    break;

                case ReportSM.STATE_FLAGS_DIFFER:     // Update startDate if new day and wait for matching flags
                    if (newDay)
                    {
                        startDate = dataItem.date;
                    }
                    if (res)                                    // Check if flags are matching
                    {
                        state     = ReportSM.STATE_FLAGS_MATCH; // Goto state for matching flags
                        startDate = dataItem.date;              // Save starting date
                    }
                    break;

                case ReportSM.STATE_FLAGS_MATCH:                      // Wait for flag difference and write result
                    if (endFlag)                                      // Its end of data and we are still in flags match state, end current "array"
                    {
                        DateTime temp = dataItem.date.AddMinutes(15); // Add minutes so temp points to new day and "00"
                        //lis.Add(new RowDataClass(flagDesc, currentCol, startDate.ToString("dd/MM/yyyy"), startDate.ToString("HH:mm"), temp.ToString("HH:mm"), "end")); // original
                        lis.Add(new FlagOccurrenceClass(flagDesc, currentCol, startDate, temp));
                        break;
                    }
                    if (newDay)     // Check if new day, new day restarts cycle
                    {
                        // It is new day, save result and start over
                        //lis.Add(new RowDataClass(flagDesc, currentCol, startDate.ToString("dd/MM/yyyy"), startDate.ToString("HH:mm"), dataItem.date.ToString("HH:mm"), "end")); // original
                        lis.Add(new FlagOccurrenceClass(flagDesc, currentCol, startDate, dataItem.date));
                        startDate = dataItem.date;
                        break;
                    }
                    // Compare result
                    if (!res)
                    {
                        state = ReportSM.STATE_FLAGS_DIFFER;
                        //lis.Add(new RowDataClass(flagDesc, currentCol, startDate.ToString("dd/MM/yyyy"), startDate.ToString("HH:mm"), dataItem.date.ToString("HH:mm"), "end"));
                        lis.Add(new FlagOccurrenceClass(flagDesc, currentCol, startDate, dataItem.date));
                    }
                    break;

                default:
                    throw new Exception("Corrupted state in ReportSM");
                }
            }
            return(lis);
        }