Example #1
0
        public static void UpdateWeek(Week week)
        {
            // Create the CloudTable object that represents the table.
            CloudTable table = _tableClient.GetTableReference("week");
            table.CreateIfNotExists();

            // Create the TableOperation
            TableOperation insertOperation = TableOperation.InsertOrReplace(week);

            // Execute the insert operation.
            table.Execute(insertOperation);
        }
        public Week Get(int year, int week, string user)
        {
            if (user.ToUpper().Equals("ALL"))
            {
                var weeks = Storage.GetWeekAll(new YearWeek { Year = year, Week = week });
                var entries = weeks.SelectMany(w => w.Entries);
                var projects = entries.Select(e => e.ProjectName).Distinct();

                var summaryWeek = new Week(year, week, user);
                var summaryEntries = new List<ProjectEntry>();

                foreach (string project in projects)
                {
                    ProjectEntry newEntry = new ProjectEntry
                    {
                        ProjectName = project,
                        TimeAllocation = (entries.Where(e => e.ProjectName.Equals(project)).Sum(e => e.TimeAllocation)) / weeks.Count(),
                    };

                    summaryEntries.Add(newEntry);
                }

                summaryWeek.Entries = summaryEntries;
                return summaryWeek;
            }
            else
            {
                var retrieved = Storage.GetWeek(new YearWeek { Year = year, Week = week }, user);

                if (retrieved != null)
                {
                    return retrieved;
                }

                return new Week(year, week, user);
            }
        }
        public void Put(DateTime date, string user, [FromBody]Week value)
        {
            if (value.Entries != null)
            {
                var projects = value.Entries.Select(e => e.ProjectName).Distinct();

                foreach (string project in projects)
                {
                    Storage.AddProject(new Project(project));
                }
            }

            var entry = new Week(date.Year, DateUtilities.NumberOfWeek(date), user)
            {
                Entries = value.Entries
            };

            Storage.UpdateWeek(entry);
        }