Exemplo n.º 1
0
        public async Task <bool> SynchrinizationACovidResultNumber()
        {
            try
            {
                var updateAdditionalDatas = new List <zModels.AdditionalData>();
                var additionalDatas       = await _zarnicaDb.AdditionalDatas.Where(m => string.IsNullOrEmpty(m.TestNum))
                                            .ToListAsync();

                if (additionalDatas.Count == 0)
                {
                    return(true);
                }
                var recruitIds = additionalDatas.Select(m => m.Id).ToList();
                var relatives  = await _zarnicaDb.Relatives.Where(m => recruitIds.Contains(m.RecruitId) &&
                                                                  m.RelativeType == zModels.Relative.TempRelative)
                                 .ToListAsync();

                var recruits = await _appDb.Recruits.Where(m => recruitIds.Contains(m.RecruitId)).ToListAsync();

                foreach (var recruit in recruits)
                {
                    var relative = relatives.FirstOrDefault(m => m.RecruitId == recruit.RecruitId);
                    if (relative == null)
                    {
                        continue;
                    }

                    var additionalData = additionalDatas.FirstOrDefault(m => m.Id == recruit.RecruitId);
                    if (additionalData == null || !string.IsNullOrEmpty(additionalData.TestNum))
                    {
                        continue;
                    }
                    additionalData.TestDate = recruit.DeliveryDate;
                    additionalData.TestNum  = relative.Fio;
                    updateAdditionalDatas.Add(additionalData);
                }

                _zarnicaDb.AdditionalDatas.UpdateRange(updateAdditionalDatas);
                await _zarnicaDb.SaveChangesAsync();

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Exemplo n.º 2
0
        public async Task <IActionResult> EditTestNumber(MedicalTestNumberEditViewModel model)
        {
            if (!Regex.IsMatch(model.TestNum, @"^\d{1,2}/\d{1,4}",
                               RegexOptions.Compiled | RegexOptions.IgnoreCase))
            {
                ModelState.AddModelError("TestNum", "Неверный формат номера справки");
            }

            if (!ModelState.IsValid)
            {
                return(new JsonResult(new { isSucceeded = false, errors = ModelState.Errors() }));
            }

            var additionalData = await _zarnicaDb.AdditionalDatas.FirstOrDefaultAsync(m => m.Id == model.Id);

            additionalData.TestNum  = model.TestNum;
            additionalData.TestDate = model.TestDate;
            _zarnicaDb.AdditionalDatas.Update(additionalData);
            await _zarnicaDb.SaveChangesAsync();

            return(new JsonResult(new { isSucceeded = true }));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> СlearEventsAndPersonal(int recruitId)
        {
            var transaction = await _zarnicaDb.Database.BeginTransactionAsync(IsolationLevel.ReadCommitted);

            try
            {
                var recruit = await _appDb.Recruits.FirstOrDefaultAsync(m => m.Id == recruitId);

                var zRecruit = await _zarnicaDb.Recruits
                               .Include(m => m.Events)
                               .FirstOrDefaultAsync(m => m.Id == recruit.RecruitId);

                var personToRecruits = await _zarnicaDb.SpecialPersonToRecruits
                                       .Where(m => m.RecruitId == zRecruit.Id).ToListAsync();

                if (personToRecruits.Any())
                {
                    _zarnicaDb.SpecialPersonToRecruits.RemoveRange(personToRecruits);
                }

                _zarnicaDb.EventControls.RemoveRange(zRecruit.Events);
                await _zarnicaDb.SaveChangesAsync();

                transaction.Commit();
                HttpContext.Session.Set("alert",
                                        new AlertViewModel(AlertType.Success, "Призывник успешно удалено!"));
            }
            catch
            {
                transaction.Rollback();
                HttpContext.Session.Set("alert",
                                        new AlertViewModel(AlertType.Error, "Ошибка при удалении призывника!"));
            }

            return(RedirectToAction("Index"));
        }