Example #1
0
        public AppAssigneeDetailDTO Edit(AppAssigneeDetailDTO model)
        {
            if (model.AppType == "TRL")
            {
                if (model.OrgPositionType == "Manager")
                {
                    model.ListOfBranches = null;
                }
                else
                {
                    model.BranchId = Guid.Empty;
                }
            }
            model.Id = DataService.Add <AppAssignee>(model);

            DataService.SaveChanges();

            var assigneeBranches = DataService.GetEntity <AppAssigneeBranch>(x => x.AssigneeId == model.Id);

            foreach (var x in assigneeBranches)
            {
                DataService.Remove(x);
            }

            if (model.AppType == "TRL")
            {
                if (model.OrgPositionType == "Manager")
                {
                    DataService.Add(new AppAssigneeBranch
                    {
                        AssigneeId = model.Id,
                        BranchId   = model.BranchId.Value
                    });
                }
                else
                {
                    model.ListOfBranches?.ForEach(branchId => DataService.Add(new AppAssigneeBranch
                    {
                        AssigneeId = model.Id,
                        BranchId   = branchId
                    }));
                }
            }
            else
            {
                model.ListOfBranches?.ForEach(branchId => DataService.Add(new AppAssigneeBranch
                {
                    AssigneeId = model.Id,
                    BranchId   = branchId
                }));
            }

            DataService.SaveChanges();

            return(model);
        }
Example #2
0
        public static async Task SaveFile(IConfiguration config, FilesViewModel model, FileStoreDTO fileStoreDto, ICommonDataService dataService)
        {
            var folderForSave = config.GetSection("FileStorePath").Value + DateTime.Now.ToString("ddMMyyyy") + "/";
            var filePath      = Path.GetFullPath(folderForSave);

            if (!Directory.Exists(filePath))
            {
                Directory.CreateDirectory(filePath);
            }

            var    newName       = Path.GetFileNameWithoutExtension(Path.GetRandomFileName()) + ".zip";
            var    tempfolder    = Path.GetTempPath();
            var    fullOrigPath  = tempfolder + model.name;
            string fullZipPath   = filePath + newName;
            var    directoryInfo = (new FileInfo(fullOrigPath)).Directory;

            directoryInfo?.Create();
            await File.WriteAllBytesAsync(fullOrigPath, Convert.FromBase64String(model.file));

            CreateZip(fullZipPath, fullOrigPath);

            FileStoreHelper.DeleteFileIfExist(fullOrigPath);
            fileStoreDto.FileName = newName;
            fileStoreDto.FilePath = fullZipPath;
            dataService.Add <FileStore>(fileStoreDto);
        }
Example #3
0
        public async Task <Guid> CreateFeedback(Guid orgEmployeeId, Guid orgId, string appSort, Guid appId)
        {
            var model = new Feedback
            {
                AppId         = appId,
                AppSort       = appSort,
                OrgId         = orgId,
                OrgEmployeeId = orgEmployeeId,
                Rating        = 0,
                Comment       = "",
                IsRated       = false
            };

            try
            {
                model.Id = _dataService.Add <Feedback>(model);
                _dataService.SaveChanges();
            }
            catch
            {
                model.Id = Guid.Empty;
            }

            return(model.Id);
        }
Example #4
0
        public async Task <IActionResult> CreateOnOpen(Guid appId, string documentType, string sort, string appType, Guid?msgId)
        {
            if (appId == Guid.Empty)
            {
                return(NotFound());
            }
            var dto = new EDocumentDetailsDTO()
            {
                EDocumentType = documentType
            };
            var id = _dataService.Add <EDocument>(dto);
            await _dataService.SaveChangesAsync();

            return(msgId == null
                ? RedirectToAction("Edit", new { id, appId, sort, appType })
                : RedirectToAction("EditMsg", new { id, msgId }));
        }
        public void SaveDecision(AppDecisionDTO model)
        {
            var decision = _dataService.GetEntity <AppDecision>(p => p.Id == model.Id).SingleOrDefault();
            var isUpdate = false;

            if (decision == null)
            {
                decision = new AppDecision();
            }
            else
            {
                _dataService.GetEntity <AppDecisionReason>(p => p.AppDecisionId == decision.Id).ToList()
                .ForEach(x => _dataService.Remove(x));
                isUpdate = true;
            }
            _objectMapper.Map(model, decision);

            foreach (var reason in model.ListOfDecisionReason)
            {
                decision.AppDecisionReasons.Add(new AppDecisionReason {
                    ReasonType = reason, AppDecisionId = decision.Id
                });
            }

            var trl = _dataService.GetEntity <TrlApplication>(p => p.Id == decision.AppId).SingleOrDefault();

            if (trl == null || string.IsNullOrEmpty(trl.ExpertiseResult) || trl.AppState == "Reviewed")
            {
                return;
            }
            trl.AppDecision = decision;

            _dataService.Add(decision, isUpdate);
            _limsExchangeService.ExportDecisionTRL(decision, isUpdate); // TODO: Сделать

            _dataService.SaveChanges();
        }
Example #6
0
 public async Task <IActionResult> AdditionalInfoToLicenseSubmit(Guid id, string type, string text)
 {
     if (string.IsNullOrEmpty(text))
     {
         return(NotFound());
     }
     if (type == "Submit")
     {
         try
         {
             await _prlAppService.SubmitAdditionalInfoToLicense(id, text);
         }
         catch (Exception e)
         {
             Log.Error(e.Message);
             return(Json(new { success = false, alert = "Виникла помилка серверу, спробуйте пізніше!" }));
         }
     }
     else if (type == "Reject")
     {
         var app = _prlAppService.DataService.GetEntity <PrlApplication>(x => x.Id == id).FirstOrDefault();
         app.BackOfficeAppState = "Reviewed";
         app.AppState           = "Reviewed";
         var decision = new AppDecision {
             Id = Guid.NewGuid(), AppId = id, DecisionType = "Denied", DecisionDescription = text
         };
         app.AppDecisionId = decision.Id;
         _dataService.Add(decision);
         await _prlAppService.DataService.SaveChangesAsync();
     }
     else
     {
         return(Json(new { success = false, alert = "Неправильно введені дані, спробуйте ще раз" }));
     }
     return(Json(new { success = true }));
 }
        public async Task <Guid> ProcessApplicationToApplication(Guid appId, Guid?licenseId = null, string sort = "", bool isBackOffice = false)
        {
            var licenseApplication = _commonDataService.GetEntity <ImlApplication>(x => x.Id == appId)
                                     .FirstOrDefault();

            if (licenseApplication == null)
            {
                Log.Error("licenseApplication == null");
                throw new NullReferenceException("Виникла помилка");
            }

            var newApplication = new ImlApplication();

            _objectMapper.Map(licenseApplication, newApplication);
            newApplication.Id = Guid.NewGuid();

            //ссылка на дочернюю заяву, из которой создана лицензия
            if (licenseId == null || licenseId == Guid.Empty)
            {
                newApplication.ParentId = licenseApplication.ParentId;
            }
            else
            {
                newApplication.ParentId = licenseId;
            }

            if (!string.IsNullOrEmpty(sort))
            {
                newApplication.AppSort = sort;
            }
            else
            {
                newApplication.AppSort = licenseApplication.AppSort;
            }

            if (isBackOffice)
            {
                newApplication.IsCreatedOnPortal  = false;
                newApplication.AppState           = null;
                newApplication.BackOfficeAppState = "Project";
            }
            else
            {
                newApplication.AppState           = "Project";
                newApplication.BackOfficeAppState = null;
                newApplication.IsCreatedOnPortal  = true;
            }

            newApplication.AppType                    = "IML";
            newApplication.ModifiedOn                 = DateTime.Now;
            newApplication.IsCheckMpd                 = false;
            newApplication.IsPaperLicense             = false;
            newApplication.IsCourierDelivery          = false;
            newApplication.IsPostDelivery             = false;
            newApplication.IsAgreeLicenseTerms        = false;
            newApplication.IsAgreeProcessingData      = false;
            newApplication.IsCourierResults           = false;
            newApplication.IsPostResults              = false;
            newApplication.IsElectricFormResults      = false;
            newApplication.IsProtectionFromAggressors = false;
            newApplication.Comment                    = "";

            newApplication.ErrorProcessingLicense = null;
            newApplication.PerformerOfExpertise   = null;
            newApplication.ExpertiseDate          = null;
            newApplication.ExpertiseResult        = null;
            newApplication.AppPreLicenseCheckId   = null;
            newApplication.AppLicenseMessageId    = null;
            newApplication.AppDecisionId          = null;
            newApplication.PerformerId            = null;
            newApplication.RegDate     = null;
            newApplication.RegNumber   = null;
            newApplication.Description = null;
            newApplication.OldLimsId   = 0;

            var organizationInfo = _commonDataService.GetEntity <OrganizationInfo>(x => x.Id == licenseApplication.OrganizationInfoId)
                                   .FirstOrDefault();

            if (organizationInfo == null)
            {
                Log.Error("organizationInfo == null");
                throw new NullReferenceException("Виникла помилка");
            }

            var newOrganizationInfo = new OrganizationInfo();

            _objectMapper.Map(organizationInfo, newOrganizationInfo);
            newOrganizationInfo.Id = Guid.NewGuid();
            if (licenseId != null)
            {
                newOrganizationInfo.IsActualInfo = false;
            }
            else
            {
                newOrganizationInfo.IsActualInfo = true;
                _commonDataService.GetEntity <OrganizationInfo>(
                    x => x.OrganizationId == licenseApplication.OrgUnitId).ToList().ForEach(x => x.IsActualInfo = false);
            }

            newApplication.OrganizationInfoId = newOrganizationInfo.Id;
            _commonDataService.Add(newOrganizationInfo);

            var licenseBranches = new List <Branch>();
            var licenseBranch   = new List <ApplicationBranch>();

            var applicationBranchesIds = _commonDataService
                                         .GetEntity <ApplicationBranch>(x => x.LimsDocumentId == licenseApplication.Id)
                                         .Select(x => x.BranchId)
                                         .Distinct()
                                         .ToList();
            var applicationBranches = _commonDataService.GetEntity <Branch>(br => applicationBranchesIds.Contains(br.Id))
                                      .ToList();

            foreach (var branch in applicationBranches)
            {
                var licBr = _objectMapper.Map <Branch>(branch);
                licBr.Id = Guid.NewGuid();
                //ссылка на дочерний обьект мпд
                licBr.ParentId      = branch.Id;
                licBr.IsFromLicense = true;
                licenseBranches.Add(licBr);

                licenseBranch.Add(new ApplicationBranch
                {
                    BranchId       = licBr.Id,
                    LimsDocumentId = newApplication.Id
                });
            }

            var applicationAssigneeBranches =
                _commonDataService.GetEntity <AppAssigneeBranch>(x => applicationBranchesIds.Contains(x.BranchId));
            var applicationAssigneeIds = applicationAssigneeBranches.Select(x => x.AssigneeId).Distinct().ToList();
            var applicationAssignee    =
                _commonDataService.GetEntity <AppAssignee>(x => applicationAssigneeIds.Contains(x.Id));
            var licenseAssigneeBranches = new List <AppAssigneeBranch>();
            var licenseAssignees        = new List <AppAssignee>();

            foreach (var assignee in applicationAssignee)
            {
                var licAssignee = _objectMapper.Map <AppAssignee>(assignee);
                licAssignee.Id            = Guid.NewGuid();
                licAssignee.IsFromLicense = true;
                licenseAssignees.Add(licAssignee);

                var assBranches = applicationAssigneeBranches.Where(x => x.AssigneeId == assignee.Id);
                foreach (var appAssigneeBranch in assBranches)
                {
                    licenseAssigneeBranches.Add(new AppAssigneeBranch
                    {
                        AssigneeId = licAssignee.Id,
                        BranchId   = licenseBranches.FirstOrDefault(br => br.ParentId == appAssigneeBranch.BranchId).Id
                    });
                }
            }


            var applicationEdocumentBranches =
                _commonDataService.GetEntity <BranchEDocument>(x => applicationBranchesIds.Contains(x.BranchId));
            var applicationEdocumentIds = applicationEdocumentBranches.Select(x => x.EDocumentId).Distinct().ToList();
            var applicationEdocuments   = _commonDataService
                                          .GetEntity <EDocument>(x => applicationEdocumentIds.Contains(x.Id)).ToList();
            var licenseEdocumentBranches = new List <BranchEDocument>();
            var licenseEdocuments        = new List <EDocument>();
            var licenseFiles             = new List <FileStore>();

            foreach (var applicationEDocument in applicationEdocuments)
            {
                var licEDocument = _objectMapper.Map <EDocument>(applicationEDocument);
                licEDocument.Id            = Guid.NewGuid();
                licEDocument.IsFromLicense = true;
                licenseEdocuments.Add(licEDocument);

                var edocBranches = applicationEdocumentBranches.Where(x => x.EDocumentId == applicationEDocument.Id);
                foreach (var branchEdocument in edocBranches)
                {
                    licenseEdocumentBranches.Add(new BranchEDocument()
                    {
                        EDocumentId = licEDocument.Id,
                        BranchId    = licenseBranches.FirstOrDefault(br => br.ParentId == branchEdocument.BranchId).Id
                    });
                }
                var fileStore = _commonDataService
                                .GetEntity <FileStore>(x => x.EntityName == "EDocument" && x.EntityId == applicationEDocument.Id).ToList();
                fileStore.ForEach(x =>
                {
                    x.EntityId = licEDocument.Id;
                    x.Id       = Guid.NewGuid();
                    licenseFiles.Add(x);
                });
            }

            var imlMedicine  = (await _commonDataService.GetDtoAsync <ImlMedicineDetailDTO>(x => x.ApplicationId == appId)).ToList();
            var imlMedicines = new List <ImlMedicine>();

            foreach (var med in imlMedicine)
            {
                var imlMed = _objectMapper.Map <ImlMedicine>(med);
                imlMed.Id            = Guid.NewGuid();
                imlMed.ApplicationId = newApplication.Id;
                imlMed.IsFromLicense = true;
                imlMedicines.Add(imlMed);
            }

            _commonDataService.Add(newApplication, false);
            licenseBranches.ForEach(branch => _commonDataService.Add(branch, false));
            licenseBranch.ForEach(appBranch => _commonDataService.Add(appBranch, false));
            licenseAssignees.ForEach(assignee => _commonDataService.Add(assignee, false));
            licenseAssigneeBranches.ForEach(assigneeBr => _commonDataService.Add(assigneeBr, false));
            licenseEdocuments.ForEach(eDoc => _commonDataService.Add(eDoc, false));
            licenseEdocumentBranches.ForEach(eDocBra => _commonDataService.Add(eDocBra, false));
            licenseFiles.ForEach(x => _commonDataService.Add(x, false));
            await _commonDataService.SaveChangesAsync();

            await _imlMedicineService.SaveMedicines(imlMedicines);

            return(newApplication.Id);
        }
Example #8
0
        public async Task <Guid> Save(BranchDetailsDTO model)
        {
            var check = model.Id == Guid.Empty;

            if (check)
            {
                model.IsFromLicense = false;
            }

            var branchId = _dataService.Add <Branch>(model);
            await _dataService.SaveChangesAsync();

            if (check)
            {
                var applicationBranch = new ApplicationBranch
                {
                    LimsDocumentId = model.ApplicationId,
                    BranchId       = branchId
                };
                _dataService.Add(applicationBranch);
                await _dataService.SaveChangesAsync();

                if (model.AppType == "TRL")
                {
                    //Вид діяльності обраний в МПД
                    var trlActivityTypeEnum = _dataService.GetEntity <EnumRecord>(x => x.Code == model.TrlActivityType)?.FirstOrDefault();
                    _dataService.Add(new EntityEnumRecords()
                    {
                        EntityId       = branchId,
                        EntityType     = "BranchApplication",
                        EnumRecordType = trlActivityTypeEnum?.EnumType,
                        EnumRecordCode = trlActivityTypeEnum?.Code
                    });

                    if (model.PharmacyId != null)
                    {
                        _dataService.Add(new PharmacyItemPharmacy()
                        {
                            PharmacyId     = model.PharmacyId.Value,
                            PharmacyItemId = branchId
                        });
                    }

                    await _dataService.SaveChangesAsync();
                }
            }
            else
            {
                if (model.AppType == "TRL")
                {
                    var pharmacyItem = _dataService.GetEntity <PharmacyItemPharmacy>(x => x.PharmacyItemId == branchId)?.FirstOrDefault();
                    if (pharmacyItem != null)
                    {
                        _dataService.Remove(pharmacyItem);
                    }

                    if (model.PharmacyId != null)
                    {
                        _dataService.Add(new PharmacyItemPharmacy()
                        {
                            PharmacyId     = model.PharmacyId.Value,
                            PharmacyItemId = branchId
                        });
                    }

                    var entityEnumRecords =
                        _dataService.GetEntity <EntityEnumRecords>(x => x.EntityId == branchId).ToList();

                    if (entityEnumRecords.Count > 0)
                    {
                        entityEnumRecords.ForEach(x => _dataService.Remove(x));
                    }

                    //Види діяльності обрані в МПД
                    var trlActivityTypeEnum = _dataService.GetEntity <EnumRecord>(x => x.Code == model.TrlActivityType)?.FirstOrDefault();
                    _dataService.Add(new EntityEnumRecords()
                    {
                        EntityId       = branchId,
                        EntityType     = "BranchApplication",
                        EnumRecordType = trlActivityTypeEnum?.EnumType,
                        EnumRecordCode = trlActivityTypeEnum?.Code
                    });

                    await _dataService.SaveChangesAsync();
                }
            }
            return(branchId);
        }
Example #9
0
        public override async Task <IActionResult> Edit(Guid id, PrlContractorDetailDTO model)
        {
            if (id != model.Id)
            {
                return(NotFound());
            }

            if (!model.ListOfBranches?.Any() ?? true)
            {
                ModelState.AddModelError("ListOfBranches", "Мае бути обрано щонайменьше одне МПД");
            }

            if (ModelState.IsValid)
            {
                try
                {
                    model.Id = _dataService.Add <PrlContractor>(model);
                    _dataService.SaveChanges();

                    var branchContractors =
                        _dataService.GetEntity <PrlBranchContractor>().Where(x => x.ContractorId == model.Id).ToList();
                    if (branchContractors.Count > 0)
                    {
                        branchContractors.ForEach(x => _dataService.Remove(x));
                    }
                    model.ListOfBranches?.ForEach(branchId => _dataService.Add(new PrlBranchContractor()
                    {
                        ContractorId = model.Id,
                        BranchId     = branchId
                    }));
                    _dataService.SaveChanges();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (await Service.GetListDTO().SingleOrDefaultAsync(x => x.Id == id) == null)
                    {
                        return(await Task.Run(() => NotFound()));
                    }
                    else
                    {
                        throw;
                    }
                }


                return(RedirectToAction("Details", "PrlApp", new { Area = "PRL", Id = model.appId }, "prlContractor"));
            }
            var branchIds = _dataService.GetEntity <PrlBranchContractor>().Where(x => x.ContractorId == model.Id).Select(x => x.BranchId);

            model.ListOfBranches = branchIds.ToList();
            IEnumerable <BranchListDTO> branchList;

            if (model.Sort == "AddBranchApplication")
            {
                branchList = await _dataService.GetDtoAsync <BranchListDTO>(x => x.ApplicationId == model.appId && x.IsFromLicense != true);
            }
            else
            {
                branchList = await _dataService.GetDtoAsync <BranchListDTO>(x => x.ApplicationId == model.appId);
            }
            ViewBag.multiSelectBranchList =
                new MultiSelectList(branchList, nameof(BranchListDTO.Id), nameof(BranchListDTO.Name));

            return(View(model));
        }
Example #10
0
        public IActionResult InfoUpdate(UserAreaDetailDTO model)
        {
            var isChangedOrg      = false;
            var isChangedEmployee = false;
            var isChangedPerson   = false;

            var userInfo           = _userInfoService.GetCurrentUserInfo();
            var userEmployeeEntity = new EmployeeExt();
            var userPersonEntity   = new Person();
            var userOrgEntity      = new OrganizationExt();

            try
            {
                Guid personGuid = userInfo.PersonId;
                userEmployeeEntity = _commonDataService.GetEntity <EmployeeExt>(org_employee => (org_employee.PersonId == userInfo.PersonId)).FirstOrDefault();
                userPersonEntity   = _commonDataService.GetEntity <Person>(person => (person.Id == userInfo.PersonId)).FirstOrDefault();
                userOrgEntity      = _commonDataService.GetEntity <OrganizationExt>(org_organization => (org_organization.Id == userEmployeeEntity.OrganizationId)).FirstOrDefault();
            }
            catch
            {
                return(NotFound());
            }

            // должность
            if (!string.IsNullOrEmpty(model.Position) && (model.Position != userEmployeeEntity.Position))
            {
                isChangedEmployee           = true;
                userEmployeeEntity.Position = model.Position;
            }

            // мейл пользователя
            if (!string.IsNullOrEmpty(model.UserEmail) && (model.UserEmail != userEmployeeEntity.UserEmail))
            {
                isChangedEmployee            = true;
                userEmployeeEntity.UserEmail = model.UserEmail;
            }

            // мейл компании
            if (!string.IsNullOrEmpty(model.OrgEmail) && (model.OrgEmail != userOrgEntity.EMail))
            {
                isChangedOrg        = true;
                userOrgEntity.EMail = model.OrgEmail;
            }

            // телефон пользователя
            if (!string.IsNullOrEmpty(model.Phone) && (model.Phone != userPersonEntity.Phone))
            {
                isChangedPerson        = true;
                userPersonEntity.Phone = model.Phone;
            }

            // оповещение ReceiveOnChangeAllApplication
            if (model.ReceiveOnChangeAllApplication != userEmployeeEntity.ReceiveOnChangeAllApplication)
            {
                isChangedEmployee = true;
                userEmployeeEntity.ReceiveOnChangeAllApplication = model.ReceiveOnChangeAllApplication;
            }

            // оповещение ReceiveOnChangeAllMessage
            if (model.ReceiveOnChangeAllMessage != userEmployeeEntity.ReceiveOnChangeAllMessage)
            {
                isChangedEmployee = true;
                userEmployeeEntity.ReceiveOnChangeAllMessage = model.ReceiveOnChangeAllMessage;
            }

            // оповещение ReceiveOnChangeOwnApplication
            if (model.ReceiveOnChangeOwnApplication != userEmployeeEntity.ReceiveOnChangeOwnApplication)
            {
                isChangedEmployee = true;
                userEmployeeEntity.ReceiveOnChangeOwnApplication = model.ReceiveOnChangeOwnApplication;
            }

            // оповещение ReceiveOnChangeOwnMessage
            if (model.ReceiveOnChangeOwnMessage != userEmployeeEntity.ReceiveOnChangeOwnMessage)
            {
                isChangedEmployee = true;
                userEmployeeEntity.ReceiveOnChangeOwnMessage = model.ReceiveOnChangeOwnMessage;
            }

            // оповещение PersonalCabinetStatus - TODO - переименовать
            if (model.PersonalCabinetStatus != userEmployeeEntity.PersonalCabinetStatus)
            {
                isChangedEmployee = true;
                userEmployeeEntity.PersonalCabinetStatus = model.PersonalCabinetStatus;
            }

            // оповещение ReceiveOnChangeOrgInfo - TODO - добавить в модель
            if (model.ReceiveOnChangeOrgInfo != userEmployeeEntity.ReceiveOnChangeOrgInfo)
            {
                isChangedEmployee = true;
                userEmployeeEntity.ReceiveOnChangeOrgInfo = model.ReceiveOnChangeOrgInfo;
            }

            // оповещение ReceiveOnOverduePayment - TODO - добавить в модель
            if (model.ReceiveOnOverduePayment != userEmployeeEntity.ReceiveOnOverduePayment)
            {
                isChangedEmployee = true;
                userEmployeeEntity.ReceiveOnOverduePayment = model.ReceiveOnOverduePayment;
            }

            try
            {
                if (isChangedPerson)
                {
                    _commonDataService.Add(userPersonEntity, true);
                }
            }
            catch
            {
                return(Json(new { success = false, errortext = "Помилка збереження інформації в базу даних (персона)!" }));
            }

            try
            {
                if (isChangedEmployee)
                {
                    _commonDataService.Add(userEmployeeEntity, true);
                }
            }
            catch
            {
                return(Json(new { success = false, errortext = "Помилка збереження інформації в базу даних (співробітник)!" }));
            }

            try
            {
                if (isChangedOrg)
                {
                    _commonDataService.Add(userOrgEntity, true);
                }
            }
            catch
            {
                return(Json(new { success = false, errortext = "Помилка збереження інформації в базу даних (організація)!" }));
            }

            if (isChangedPerson || isChangedEmployee || isChangedOrg)
            {
                _commonDataService.SaveChanges();
            }

            return(Json(new { success = true, errortext = "Зміна даних користувача пройшла успішно!" }));
        }
Example #11
0
        public async Task <List <string> > UploadMedicine(Guid?appId, IFormFile file)
        {
            var countOfErrors = 0;
            var cellErrors    = new List <string>();
            var medicines     = new List <ImlMedicine>();

            using (var excelPackage = new ExcelPackage(file.OpenReadStream()))
            {
                var workbook    = excelPackage.Workbook;
                var worksheet   = workbook.Worksheets.First();
                var row         = 9;
                var checkString = "";
                var limsRps     = await DataService.GetDtoAsync <LimsRPMinDTO>(x => x.EndDate > DateTime.Now && x.OffOrderDate == null, extraParameters : new object[] { "" });

                do
                {
                    var    imlMedicine  = new ImlMedicine();
                    var    checkOnError = false;
                    string cellNum      = "";
                    for (var col = 1; col < 14; col++)
                    {
                        var cell     = worksheet.Cells[row, col].First();
                        var valueObj = cell.Value;
                        if (valueObj != null)
                        {
                            var value = valueObj.ToString();
                            switch (col)
                            {
                            case 1:
                                cellNum = value;
                                break;

                            case 2:
                                imlMedicine.MedicineName = value;
                                checkString = value;
                                break;

                            case 3:
                                if (string.IsNullOrEmpty(value))
                                {
                                    checkOnError = true;
                                }
                                imlMedicine.FormName = value;
                                break;

                            case 4:
                                if (string.IsNullOrEmpty(value))
                                {
                                    checkOnError = true;
                                }
                                imlMedicine.DoseInUnit = value;
                                break;

                            case 5:
                                if (string.IsNullOrEmpty(value))
                                {
                                    checkOnError = true;
                                }
                                imlMedicine.NumberOfUnits = value;
                                break;

                            case 6:
                                if (string.IsNullOrEmpty(value))
                                {
                                    checkOnError = true;
                                }
                                imlMedicine.MedicineNameEng = value;
                                break;

                            case 7:
                                if (string.IsNullOrEmpty(value))
                                {
                                    checkOnError = true;
                                }
                                var rplz = limsRps.FirstOrDefault(x => x.RegNum == value);
                                if (rplz == null)
                                {
                                    cellErrors.Add(cellNum);
                                    checkOnError = true;
                                    break;
                                }
                                else
                                {
                                    imlMedicine.LimsRpId = rplz.Id;
                                }

                                imlMedicine.RegisterNumber = value;
                                break;

                            case 8:
                                if (string.IsNullOrEmpty(value))
                                {
                                    checkOnError = true;
                                }
                                imlMedicine.AtcCode = value;
                                break;

                            case 9:
                                if (string.IsNullOrEmpty(value))
                                {
                                    checkOnError = true;
                                }
                                imlMedicine.ProducerName = value;
                                break;

                            case 10:
                                if (string.IsNullOrEmpty(value))
                                {
                                    checkOnError = true;
                                }
                                imlMedicine.ProducerCountry = value;
                                break;

                            case 11:
                                if (string.IsNullOrEmpty(value))
                                {
                                    checkOnError = true;
                                }
                                imlMedicine.SupplierName = value;
                                break;

                            case 12:
                                if (string.IsNullOrEmpty(value))
                                {
                                    checkOnError = true;
                                }
                                imlMedicine.SupplierCountry = value;
                                break;

                            case 13:
                                if (string.IsNullOrEmpty(value))
                                {
                                    checkOnError = true;
                                }
                                imlMedicine.SupplierAddress = value;
                                break;

                            case 14:
                                if (string.IsNullOrEmpty(value))
                                {
                                    checkOnError = true;
                                }
                                imlMedicine.Notes = value;
                                break;
                            }
                        }
                        else
                        {
                            if (col == 2)
                            {
                                checkString  = string.Empty;
                                checkOnError = true;
                                break;
                            }
                        }

                        //if (checkOnError)
                        //    break;
                    }

                    imlMedicine.ApplicationId = appId.Value;
                    imlMedicine.CreatedByJson = _userInfo.PersonId;

                    if (!checkOnError)
                    {
                        medicines.Add(imlMedicine);
                    }
                    //else
                    //    countOfErrors++;

                    row++;
                } while (!string.IsNullOrEmpty(checkString));

                await SaveMedicines(medicines);
            }
            var fileStore = new FileStoreDTO
            {
                FileType     = FileType.Unknown,
                OrigFileName = file.Name + ".xlsx",
                FileSize     = file.Length,
                Ock          = false,
                EntityId     = appId.Value,
                EntityName   = nameof(ImlApplication),
                ContentType  = ".xlsx",
                Description  = "Medicines"
            };
            var dto = FileStoreHelper.SaveFile(_configuration, file, fileStore);

            DataService.Add <FileStore>(dto);
            await DataService.SaveChangesAsync();

            return(cellErrors);
        }
Example #12
0
        public async Task <IActionResult> ListPayment(Guid appId, string appType)
        {
            var eDocumentAppList = (await _dataService.GetDtoAsync <EDocumentPaymentListDTO>(
                                        p => p.EdocumentType == "PaymentDocument",
                                        extraParameters: new object[] { $"\'{appId}\'" })).ToList();

            string entityName = appType == "PRL" ? "PrlApplication" : appType == "IML" ? "ImlApplication" : "TrlApplication";

            ViewBag.AppType = appType;
            var dto = new EDocumentDetailsDTO();

            if (eDocumentAppList.Count == 0)
            {
                dto = new EDocumentDetailsDTO()
                {
                    Id              = Guid.NewGuid(),
                    EDocumentType   = "PaymentDocument",
                    EDocumentStatus = "RequiresPayment",
                    EntityName      = entityName,
                    EntityId        = appId,
                    DateFrom        = DateTime.Now
                };
                _dataService.Add <EDocument>(dto);
                await _dataService.SaveChangesAsync();

                return(PartialView("ListPayment", dto));
            }

            var notVerified = eDocumentAppList.Where(p => p.EdocumentStatus == "PaymentNotVerified")
                              .OrderByDescending(p => p.CreatedOn).FirstOrDefault();
            var docRequires = eDocumentAppList.SingleOrDefault(p => p.EdocumentStatus == "RequiresPayment");

            if (docRequires != null)
            {
                dto = (await _dataService.GetDtoAsync <EDocumentDetailsDTO>(p => p.Id == docRequires.Id,
                                                                            extraParameters: new object[] { $"\'{docRequires.EntityId}\'" })).SingleOrDefault();
                dto.Comment = notVerified?.Comment;

                return(PartialView("ListPayment", dto));
            }

            docRequires = eDocumentAppList.SingleOrDefault(p => p.EdocumentStatus == "WaitingForConfirmation" || p.EdocumentStatus == "PaymentConfirmed");
            if (docRequires != null)
            {
                return(PartialView("ListPayment", new EDocumentDetailsDTO
                {
                    Id = docRequires.Id,
                    EDocumentStatus = docRequires.EdocumentStatus,
                    EntityId = docRequires.EntityId
                }));
            }

            //if PaymentNotVerified
            dto = new EDocumentDetailsDTO()
            {
                Id              = Guid.NewGuid(),
                EDocumentType   = "PaymentDocument",
                EDocumentStatus = "RequiresPayment",
                EntityName      = entityName,
                EntityId        = appId,
                DateFrom        = DateTime.Now
            };
            _dataService.Add <EDocument>(dto);
            await _dataService.SaveChangesAsync();

            dto.Comment = notVerified?.Comment;
            return(PartialView("ListPayment", dto));
        }