Exemple #1
0
        public void UpdateEntry(dtoEntry entry)
        {
            var output = _entryService.UpdateEntry(entry);

            if (!output)
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }
        }
Exemple #2
0
        public HttpResponseMessage CreateEntry(dtoEntry entry)
        {
            var output = _entryService.CreateEntry(entry);

            if (output)
            {
                var response = Request.CreateResponse(HttpStatusCode.Created);
                return(response);
            }
            else
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }
        }
Exemple #3
0
        public bool CreateEntry(dtoEntry entry)
        {
            try
            {
                var newEntry = Mapper.Map <dtoEntry, Entry>(entry);

                var entryHeader = unitOfWork.GetEntryRepository().GetById(newEntry.EntryHeader_Id);
                entryHeader.Entries.Add(newEntry);
                unitOfWork.Save();
            }
            catch (Exception)
            {
                return(false);
            }
            return(true);
        }
Exemple #4
0
        public bool UpdateEntry(dtoEntry entry)
        {
            try
            {
                var entryHeader = unitOfWork.GetEntryRepository().GetById(entry.EntryHeader_Id);
                var item        = entryHeader.Entries.SingleOrDefault(e => e.Id == entry.Id);

                if (item != null)
                {
                    item.Hours = entry.Hours;
                    item.Notes = entry.Notes;
                }

                unitOfWork.Save();
            }
            catch (Exception)
            {
                return(false);
            }
            return(true);
        }
Exemple #5
0
        public IList <dtoEntryHeader> GetEntries(DateTime startDate, DateTime endDate, int userId)
        {
            var entries = unitOfWork.GetEntryRepository()
                          .Get(e => e.WeekStartDate >= startDate &&
                               e.WeekStartDate <= endDate &&
                               e.User_Id == userId
                               ).ToList();

            List <dtoEntryHeader> result = Mapper.Map <List <EntryHeader>, List <dtoEntryHeader> >(entries);
            DateTime tempDate;

            // fill dates with blank entries
            foreach (dtoEntryHeader header in result)
            {
                List <dtoEntry> blankEntries = new List <dtoEntry>();
                tempDate = startDate;
                while (tempDate <= endDate)
                {
                    var entry = header.Entries.SingleOrDefault(e => e.EntryDate == tempDate);
                    if (entry == null)
                    {
                        blankEntries.Add(new dtoEntry()
                        {
                            EntryDate = tempDate,
                        });
                    }
                    tempDate = tempDate.AddDays(1);
                }

                foreach (var blankEntry in blankEntries)
                {
                    header.Entries.Add(blankEntry);
                }
                header.Entries = header.Entries.OrderBy(e => e.EntryDate).ToList();
                // calculate total line hours
                header.TotalHours = header.Entries.Sum(e => e.Hours);
            }

            // create total hours row
            dtoEntryHeader totalHeader = new dtoEntryHeader()
            {
                IsTotal = true,
                Entries = new Collection <dtoEntry>()
            };

            Decimal grandTotal = 0;

            tempDate = startDate;
            while (tempDate <= endDate)
            {
                List <decimal> listTempTotals = new List <decimal>();
                result.ForEach(p => listTempTotals.Add(p.Entries.Where(e => e.EntryDate == tempDate).Sum(s => s.Hours)));
                tempDate = tempDate.AddDays(1);

                var totalEntry = new dtoEntry
                {
                    EntryDate = tempDate,
                    Hours     = listTempTotals.Sum()
                };
                totalHeader.Entries.Add(totalEntry);
                grandTotal += totalEntry.Hours;
            }
            totalHeader.Entries.Add(new dtoEntry()
            {
                Hours = grandTotal
            });
            result.Add(totalHeader);

            return(result);
        }