Esempio n. 1
0
        public async Task <IActionResult> PutQuestionReply([FromRoute] int id, [FromBody] QuestionReply questionReply)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != questionReply.QuestionReplyId)
            {
                return(BadRequest());
            }

            _context.Entry(questionReply).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!QuestionReplyExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Esempio n. 2
0
        public async Task <IActionResult> PutAgedCareCenter([FromRoute] int id, [FromBody] AgedCareCenter agedCareCenter)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != agedCareCenter.AgedCareCenterId)
            {
                return(BadRequest());
            }

            _context.Entry(agedCareCenter).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AgedCareCenterExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> PutAccreditationStandart([FromRoute] int id, [FromBody] AccreditationStandart accreditationStandart)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != accreditationStandart.AccreditationStandartId)
            {
                return(BadRequest());
            }

            _context.Entry(accreditationStandart).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AccreditationStandartExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Esempio n. 4
0
        public async Task <IActionResult> GetNewReport([FromRoute] int assessorId, [FromRoute] int agedCareCenterId)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var report = new Report
            {
                AgedCareCenterId = agedCareCenterId,
                AssessorId       = assessorId,
                ReportDate       = DateTime.Now,
            };

            report.QuestionReply = _context.Questions.Select(q => new QuestionReply {
                QuestionId = q.QuestionId, Response = false
            }).ToList();

            _context.Reports.Add(report);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetNewReport", new { id = report.ReportId }, report));
        }
Esempio n. 5
0
        public async Task <IActionResult> Sync([FromBody] List <Report> reports)
        {
            if (!ModelState.IsValid)
            {
                var errorsModel = new StringBuilder();
                foreach (var modelState in ModelState.Values)
                {
                    foreach (var error in modelState.Errors)
                    {
                        if (error.Exception != null)
                        {
                            errorsModel.AppendLine(error.Exception.Message);
                        }
                        else if (error.ErrorMessage != null)
                        {
                            errorsModel.AppendLine(error.ErrorMessage);
                        }
                    }
                }
                var res = new SyncModel()
                {
                    Error = errorsModel.ToString()
                };
                return(CreatedAtAction("Sync", res));
            }

            var CryptInfo = this.HttpContext.Request.Headers["CryptInfo"];

            if (CryptInfo.Count == 0)
            {
                var res = new SyncModel()
                {
                    Error = "Login failed."
                };
                return(CreatedAtAction("Sync", res));
            }

            _logger.LogInformation("sync...");

            if (reports == null)
            {
                _logger.LogInformation("sync...request is null");
            }
            else
            {
                _logger.LogInformation($"sync...request '{CryptInfo[0]}'");
            }

            var           model = new SyncModel();
            StringBuilder sb    = new StringBuilder();

            try
            {
                var userId = CheckUser(CryptInfo[0]);

                try
                {
                    if (reports != null)
                    {
                        foreach (var report in reports)
                        {
                            if (report.AgedCareCenterId == -1 || report.AssessorId == -1)
                            {
                                continue;
                            }

                            if (report.IsDeleted)
                            {
                                if (report.QuestionReply != null)
                                {
                                    foreach (var reply in report.QuestionReply)
                                    {
                                        if (reply.QuestionReplyId != 0)
                                        {
                                            _context.Remove(reply);
                                        }
                                    }
                                }
                                _logger.LogInformation($"INFO Delete...report #'{report.ReportId}'");
                                _context.Remove(report);
                                await _context.SaveChangesAsync();
                            }
                            else if (report.IsNew)
                            {
                                _logger.LogInformation($"INFO Inser new...report'{report.ReportDate}'");
                                await _context.SaveReport(report);
                            }
                            else if (report.IsChanged)
                            {
                                _logger.LogInformation($"INFO Update...report #'{report.ReportId}'");
                                await _context.UpdateReport(report);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    _logger.LogError(ex, "ReportSyncError");
                    sb.AppendLine(ex.Message);
                }

                model.AccreditationStandartList = await _context.AccreditationStandarts.Include(acc => acc.Questions).ToListAsync();

                model.AgedCareCenterList = await _context.AgedCareCenters.ToListAsync();

                model.AssessorList = await _context.Assessors.ToListAsync();

                var Questions = await _context.Questions.Include(q => q.Questions).GroupBy(q => q.AccreditationStandartId).ToListAsync();

                model.ReportList = await _context.GetReportsWithReplies(userId);

                var newReport = new Report
                {
                    AgedCareCenterId = -1,
                    AssessorId       = -1,
                    ReportDate       = DateTime.Now,
                    IsNew            = true
                };
                var questionReplyList =
                    from asst in model.AccreditationStandartList
                    from q in asst.Questions
                    select new QuestionReply(q);

                newReport.QuestionReply = questionReplyList.SelectMany(q => q.SubQuestionList).ToList();
                model.NewReport         = newReport;
                model.ReportList
                .ForEach(r =>
                {
                    foreach (var item in r.QuestionReply)
                    {
                        var q = item.Question;
                        if (item.Question.ParentId.HasValue)
                        {
                            item.QuestionParentId = item.Question.ParentId.Value;
                            q = item.Question.Parent;
                        }
                        item.AccreditationStandartId = q.AccreditationStandartId.Value;
                    }
                    var questionNumberOrderBy = 0;
                    //r.QuestionReply.GroupBy(qr => qr.Question.AccreditationStandartId)
                    //                .SelectMany(g => g.OrderBy(q => q.QuestionId)
                    //                .GroupBy(qr2 => qr2.QuestionParentId)
                    //                .SelectMany(g2 => g2.OrderBy(q => q.QuestionId)
                    //                .Select((qr, i) =>
                    //                               {
                    //                                   questionNumberOrderBy++;
                    //                                   qr.QuestionNumber = $"{g.Key}.{i + 1}";
                    //                                   return qr.QuestionNumber;
                    //                               }))
                    //                             .ToList();
                    //r.QuestionReply = r.QuestionReply.OrderBy(qr => qr.AccreditationStandartId).ToList();
                });
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "MobileSync");
                sb.AppendLine(ex.Message);
            }
            finally
            {
                var message = sb.ToString();
                model.Error = message;
            }

            return(CreatedAtAction("Sync", model));
        }