예제 #1
0
        public long CreateReport(ReportItemDto report)
        {
            if (DateTime.Parse(report.Date).Date > DateTime.Now.Date || _context.Reports.Where(x => x.UserID == report.UserID && x.Date.Date == DateTime.Parse(report.Date).Date).Any())
            {
                return(-1);
            }

            var currentReport = _context.Reports.Where(x => x.UserID == report.UserID && x.Date.Date == DateTime.Parse(report.Date).Date).SingleOrDefault();

            if (currentReport != null)
            {
                _context.Reports.Remove(currentReport);
            }

            var newReport = new Report
            {
                UserID   = report.UserID,
                Name     = report.Name,
                Surname  = report.Surname,
                Sector   = report.Sector.SectorName,
                WorkName = report.Sector.WorkName,
                Amount   = Math.Round(report.Amount, 2),
                Hours    = Math.Round(report.Hours, 2),
                Date     = DateTime.Parse(report.Date),
            };

            _context.Reports.Add(newReport);
            _context.SaveChanges();

            return(newReport.Id);
        }
예제 #2
0
        public async Task <ActionResult> Customize(Guid key, string reportName, ReportItemDto reportItemDto)
        {
            var requestDispatcher = CreateAsyncRequestDispatcher();

            requestDispatcher.Add(new SaveReportCustomizationModelRequest {
                SourceKey = key, ReportName = reportName, ReportItemDto = reportItemDto
            });
            await requestDispatcher.GetAsync <SaveReportCustomizationModelResponse> ();

            return(null);
        }
        public async Task <IActionResult> UpdateReportItem([FromBody] ReportItemDto reportItemDto)
        {
            if (reportItemDto == null)
            {
                return(BadRequest());
            }

            await _iReportItemService.Update(reportItemDto);

            return(Ok($"Updated report with id = {reportItemDto.Id}"));
        }
 public static ReportItem MapDtoToReportItem(ReportItemDto reportItemDto)
 {
     return(new ReportItem()
     {
         Id = reportItemDto.Id.GetValueOrDefault(),
         Content = reportItemDto.Content,
         Notes = reportItemDto.Notes,
         SourceType = reportItemDto.SourceType,
         Ip = reportItemDto.Ip,
         IsChecked = reportItemDto.IsChecked
     });
 }
예제 #5
0
        //
        // Report Item
        //
        private static ReportItemDto Convert(Report report)
        {
            if (report == null)
            {
                return(null);
            }
            ReportItemDto reportdto = new ReportItemDto
            {
                date       = report.date.ToString(),
                count      = report.count,
                commission = report.commission
            };

            return(reportdto);
        }
예제 #6
0
        public static Report Convert(ReportItemDto reportDto)
        {
            if (reportDto == null)
            {
                return(null);
            }
            Report report = new Report()
            {
                Date  = DateTime.Parse(reportDto.Date),
                Count = reportDto.Count,
                Price = reportDto.Price
            };

            return(report);
        }
예제 #7
0
        public static ReportItemDto Convert(Report report)
        {
            if (report == null)
            {
                return(null);
            }
            ReportItemDto reportDto = new ReportItemDto()
            {
                Date  = report.Date.ToString(),
                Count = report.Count,
                Price = report.Price
            };

            return(reportDto);
        }
예제 #8
0
        private static ObservableCollection <ReportItemDto> GetCollection(IList <ReportItemDto> Items, string period, DateTime start, DateTime stop)
        {
            ObservableCollection <ReportItemDto> Collection = new ObservableCollection <ReportItemDto>();

            if (Items == null)
            {
                return(null);
            }

            switch (period)
            {
            case "day":
            {
                DateTime d = start;
                while (d <= stop)
                {
                    ReportItemDto repItem = new ReportItemDto
                    {
                        date       = d.Date.ToString("dd.MM.yyyy"),
                        count      = 0,
                        commission = 0
                    };
                    foreach (var item in Items)
                    {
                        if (Convert.ToDateTime(item.date).Date == d)
                        {
                            repItem.count      += item.count;
                            repItem.commission += item.commission;
                        }
                    }
                    Collection.Add(repItem);
                    d = d.AddDays(1);
                }
                break;
            }

            case "month":
            {
                DateTime d = start;
                while (d <= stop)
                {
                    ReportItemDto repItem = new ReportItemDto
                    {
                        date       = d.Date.ToString("Y"),
                        count      = 0,
                        commission = 0
                    };
                    foreach (var item in Items)
                    {
                        if ((Convert.ToDateTime(item.date).Month == d.Month) && (Convert.ToDateTime(item.date).Year == d.Year))
                        {
                            repItem.count      += item.count;
                            repItem.commission += item.commission;
                        }
                    }
                    Collection.Add(repItem);
                    d = d.AddMonths(1);
                }
                break;
            }

            case "year":
            {
                DateTime d = start;
                while (d <= stop)
                {
                    ReportItemDto repItem = new ReportItemDto
                    {
                        date       = d.Date.Year.ToString(),
                        count      = 0,
                        commission = 0
                    };
                    foreach (var item in Items)
                    {
                        if (Convert.ToDateTime(item.date).Year == d.Year)

                        {
                            repItem.count      += item.count;
                            repItem.commission += item.commission;
                        }
                    }
                    Collection.Add(repItem);
                    d = d.AddYears(1);
                }
                break;
            }
            }
            return(Collection);
        }
예제 #9
0
        private static ObservableCollection <ReportItemDto> GetCollection(IList <ReportItemDto> Items, string period, DateTime start, DateTime stop)
        {
            ObservableCollection <ReportItemDto> Collection = new ObservableCollection <ReportItemDto>();

            // Условие проверки наличия принятых данных.
            if (Items == null)
            {
                return(null);
            }

            switch (period)
            {
            case "day":
            {
                DateTime d = start;
                while (d <= stop)
                {
                    ReportItemDto repItem = new ReportItemDto
                    {
                        date  = d.Date.ToString("dd.MM.yyyy"),
                        count = 0,
                        price = 0
                    };
                    foreach (var item in Items)
                    {
                        if (Convert.ToDateTime(item.date).Date == d)
                        {
                            repItem.count += item.count;
                            repItem.price += item.price;
                        }
                    }
                    Collection.Add(repItem);
                    d = d.AddDays(1);
                }
                break;
            }

            case "month":
            {
                DateTime d = start;
                while (d <= stop)
                {
                    ReportItemDto repItem = new ReportItemDto
                    {
                        date  = d.Date.ToString("Y"),
                        count = 0,
                        price = 0
                    };
                    foreach (var item in Items)
                    {
                        if ((Convert.ToDateTime(item.date).Month == d.Month) && (Convert.ToDateTime(item.date).Year == d.Year))
                        {
                            repItem.count += item.count;
                            repItem.price += item.price;
                        }
                    }
                    Collection.Add(repItem);
                    d = d.AddMonths(1);
                }
                break;
            }

            case "year":
            {
                DateTime d = start;
                while (d <= stop)
                {
                    ReportItemDto repItem = new ReportItemDto
                    {
                        date  = d.Date.Year.ToString(),
                        count = 0,
                        price = 0
                    };
                    foreach (var item in Items)
                    {
                        if (Convert.ToDateTime(item.date).Year == d.Year)

                        {
                            repItem.count += item.count;
                            repItem.price += item.price;
                        }
                    }
                    Collection.Add(repItem);
                    d = d.AddYears(1);
                }
                break;
            }
            }
            // Возвращаем коллекцию.
            return(Collection);
        }
예제 #10
0
 public async Task Update(ReportItemDto singleResultDto)
 {
     await _iReportItemRepository.Update(ReportItemMapper.MapDtoToReportItem(singleResultDto));
 }
예제 #11
0
 public long Create(ReportItemDto report)
 {
     return(reportService.CreateReport(report));
 }