Example #1
0
        public async Task <IActionResult> UpdateReportStructure([FromBody] UpdateReportStructureFormModel form)
        {
            var result =
                await _reportService.AddOrUpdateReportStructureAsync(HttpContext.GetUser(), form);

            return(Ok(GetRequestResult(result)));
        }
Example #2
0
        public async Task <bool> AddOrUpdateReportStructureAsync(User user, UpdateReportStructureFormModel form)
        {
            try
            {
                var resp = await _context.ReportStructures.FirstOrDefaultAsync(c => c.Id == form.ReportStructureModelId || c.ReportId == form.ReportId);

                if (resp is null && form.ReportStructureModelId != 0)
                {
                    throw new StockAssistanceProviderGlobalException(ReportServiceErrors.ReportStructureNotFoundError);
                }
                if (resp != null)
                {
                    resp.Configuration       = form.Configuration;
                    resp.LastUpdatedDateTime = DateTime.Now;
                    resp.ReportId            = form.ReportId;
                    _context.ReportStructures.Update(resp);
                }
                else
                {
                    var report = new ReportStructure()
                    {
                        Configuration       = form.Configuration,
                        CreationDate        = DateTime.Now,
                        LastUpdatedDateTime = DateTime.Now,
                        ReportId            = form.ReportId
                    };
                    await _context.ReportStructures.AddAsync(report);
                }
                await _context.SaveChangesAsync();

                return(true);
            }
            catch (Exception ex)
            {
                throw new StockAssistanceProviderGlobalException(ReportServiceErrors.UpdateReportStructureError, ex);
            }
        }