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 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);
        }
        public ValidateResult CreateDocument(Guid id, DocumentDto dto)
        {
            //TEntity entity = this.dataService.GetById<TEntity>(id);
            //if (entity == null)
            //{
            //    return new ValidateResult("notFound");
            //}

            bool        tryParseFileId = Guid.TryParse(dto.FileId, out Guid fileId);
            FileStorage file           = dataService.GetDbSet <FileStorage>().FirstOrDefault(x => x.Id == fileId);

            if (!tryParseFileId || file == null)
            {
                return(new ValidateResult("notFound"));
            }

            Guid?typeId = null;

            if (!string.IsNullOrEmpty(dto.TypeId) && Guid.TryParse(dto.TypeId, out Guid tId))
            {
                typeId = tId;
            }

            var document = new Document
            {
                Name          = dto.Name,
                PersistableId = id,
                FileId        = fileId,
                TypeId        = typeId
            };

            _historyService.Save(id, "documentAttached", file.Name);

            dataService.GetDbSet <Document>().Add(document);
            dataService.SaveChanges();

            return(new ValidateResult
            {
                Id = document.Id.ToString()
            });
        }
Example #4
0
        public bool SaveChangingInfoAsync(Guid id, string _string)
        {
            var branch = _dataService.GetEntity <Branch>(x => x.Id == id).SingleOrDefault();

            if (branch == null)
            {
                return(false);
            }
            branch.OperationListFormChanging = _string;
            _dataService.SaveChanges();
            return(true);
        }
        public void Execute()
        {
            var orderChanges     = _dataService.GetChanges <Order>().ToList();
            var shippingChanges  = _dataService.GetChanges <Shipping>().ToList();
            var tariffChanges    = _dataService.GetChanges <Tariff>().ToList();
            var warehouseChanges = _dataService.GetChanges <Warehouse>().ToList();

            _dataService.SaveChanges();

            RunTriggers(orderChanges);
            RunTriggers(shippingChanges);
            RunTriggers(tariffChanges);
            RunTriggers(warehouseChanges);
        }
Example #6
0
        public ValidateResult ToggleHiddenState(ToggleHiddenStateDto dto)
        {
            var dbSet = _dataService.GetDbSet <FieldPropertyItemVisibility>();

            var forEntity = Enum.Parse <FieldPropertiesForEntityType>(dto.ForEntity, true);

            var roleId = string.IsNullOrEmpty(dto.RoleId)
                ? (Guid?)null
                : Guid.Parse(dto.RoleId);


            var visibilityItem = dbSet.SingleOrDefault(x => x.ForEntity == forEntity &&
                                                       x.RoleId == roleId &&
                                                       x.FieldName == dto.FieldName);

            if (visibilityItem == null)
            {
                visibilityItem = new FieldPropertyItemVisibility
                {
                    Id        = Guid.NewGuid(),
                    ForEntity = forEntity,
                    RoleId    = roleId,
                    FieldName = dto.FieldName,
                    IsHidden  = true
                };
                dbSet.Add(visibilityItem);
            }
            else
            {
                visibilityItem.IsHidden = !visibilityItem.IsHidden;
            }

            _dataService.SaveChanges();

            return(new ValidateResult());
        }
Example #7
0
        public bool ChangePaymentStatus(Guid appId, string status, string comment = null)
        {
            var edoc = _commonDataService.GetEntity <EDocument>(p => p.EDocumentType == "PaymentDocument" && p.EntityId == appId);

            EDocument activeEdoc;

            switch (status)
            {
            case "WaitingForConfirmation":
                activeEdoc = edoc.SingleOrDefault(p => p.EDocumentStatus == "RequiresPayment");

                var files = _commonDataService.GetDto <FileStoreDTO>(p => p.EntityId == activeEdoc.Id).ToList();
                if (files.Count <= 0)
                {
                    return(false);
                }
                break;

            case "PaymentNotVerified":
            case "PaymentConfirmed":
                activeEdoc = edoc.SingleOrDefault(p => p.EDocumentStatus == "WaitingForConfirmation");
                break;

            default:
                return(false);
            }

            if (activeEdoc == null)
            {
                return(false);
            }

            activeEdoc.EDocumentStatus = status;
            activeEdoc.Comment         = comment;
            _commonDataService.SaveChanges();

            return(true);
        }
        public void SaveExpertise(TrlAppExpertiseDTO model)
        {
            var trl = _dataService.GetEntity <TrlApplication>(p => p.Id == model.Id).SingleOrDefault();

            if (trl == null)
            {
                return;
            }

            var orgUnitId = trl.OrgUnitId;

            _objectMapper.Map(model, trl);
            trl.ExpertiseResult      = model.ExpertiseResultEnum;
            trl.PerformerOfExpertise = model.PerformerOfExpertiseId;
            trl.OrgUnitId            = orgUnitId;

            _dataService.SaveChanges();
            _limsExchangeService.UpdateExpertiseTRL(model); // сделал, но нет экспертизы в заяве ,
        }
Example #9
0
        protected DetailedValidationResult SaveOrCreateInner(TListDto dto, bool isImport)
        {
            string    entityName = typeof(TEntity).Name;
            Stopwatch sw         = new Stopwatch();

            sw.Start();

            var dbSet = _dataService.GetDbSet <TEntity>();

            var entity = isImport ? FindByKey(dto) : FindById(dto);
            var isNew  = entity == null;

            Log.Information("{entityName}.SaveOrCreateInner (Find entity): {ElapsedMilliseconds}ms", entityName,
                            sw.ElapsedMilliseconds);
            sw.Restart();

            if (isNew)
            {
                entity = new TEntity
                {
                    Id = Guid.NewGuid()
                };
            }
            else if (isImport)
            {
                dto.Id = entity.Id.ToString();
            }

            // Validation step

            var result = ValidateDto(dto);

            if (result.IsError)
            {
                Log.Information($"Не удалось сохранить запись в справочник {typeof(TEntity)}: {result.Error}.");
                return(result);
            }

            // Mapping

            MapFromDtoToEntity(entity, dto);

            if (isNew)
            {
                dbSet.Add(entity);
            }

            var changes = this._dataService.GetChanges <TEntity>().FirstOrDefault(x => x.Entity.Id == entity.Id);

            // Change handlers

            var setter = this.ConfigureHandlers(this._fieldSetterFactory.Create <TEntity>(), dto);

            if (setter != null)
            {
                setter.Appy(changes);
            }

            var trackConfig = this.ConfigureChangeTacker();

            if (trackConfig != null)
            {
                trackConfig.LogTrackedChanges(changes);
            }

            Log.Information("{entityName}.SaveOrCreateInner (Apply updates): {ElapsedMilliseconds}ms", entityName,
                            sw.ElapsedMilliseconds);
            sw.Restart();

            result.Id = entity.Id.ToString();
            if (isNew)
            {
                result.ResultType = ValidateResultType.Created;
            }
            else
            {
                //dbSet.Update(entityFromDb);
                result.ResultType = ValidateResultType.Updated;
            }

            _triggersService.Execute();
            Log.Information("{entityName}.SaveOrCreateInner (Execure triggers): {ElapsedMilliseconds}ms", entityName,
                            sw.ElapsedMilliseconds);
            sw.Restart();

            _dataService.SaveChanges();
            Log.Information("{entityName}.SaveOrCreateInner (Save changes): {ElapsedMilliseconds}ms", entityName,
                            sw.ElapsedMilliseconds);

            Log.Information($"Запись {entity.Id} в справочнике {typeof(TEntity)} {(isNew ? "создана" : "обновлена")}.");

            return(result);
        }
Example #10
0
        public ValidateResult Save(SaveProfileDto dto)
        {
            var currentUserId = _userProvider.GetCurrentUserId();
            var user          = _dataService.GetDbSet <User>().GetById(currentUserId.Value);

            var lang = _userProvider.GetCurrentUser().Language;

            var result = _validationService.Validate(dto);

            if (string.IsNullOrEmpty(dto.Email))
            {
                result.AddError(nameof(dto.Email), "userEmailIsEmpty".Translate(lang),
                                ValidationErrorType.ValueIsRequired);
            }

            if (!string.IsNullOrEmpty(dto.Email) && !IsValidEmail(dto.Email))
            {
                result.AddError(nameof(dto.Email), "userEmailIsInvalid".Translate(lang),
                                ValidationErrorType.InvalidValueFormat);
            }

            if (_dataService.GetDbSet <User>().Any(x => x.Email == dto.Email && x.Id != user.Id))
            {
                result.AddError(nameof(dto.Email), "User.DuplicatedRecord".Translate(lang),
                                ValidationErrorType.DuplicatedRecord);
            }

            if (string.IsNullOrEmpty(dto.UserName))
            {
                result.AddError(nameof(dto.UserName), "userNameIsEmpty".Translate(lang),
                                ValidationErrorType.ValueIsRequired);
            }

            if (result.IsError)
            {
                return(result);
            }

            user.Email = dto.Email;
            user.Name  = dto.UserName;

            if (user.PoolingLogin != dto.PoolingLogin || user.PoolingPassword != dto.PoolingPassword)
            {
                user.PoolingLogin    = dto.PoolingLogin;
                user.PoolingPassword = dto.PoolingPassword;

                if (!string.IsNullOrEmpty(dto.PoolingLogin) && !string.IsNullOrEmpty(dto.PoolingPassword))
                {
                    using (var pooling = new PoolingIntegration(user,
                                                                _dataService, _serviceProvider))
                        pooling.Init();
                }
            }

            user.FmCPLogin    = dto.FmCPLogin;
            user.FmCPPassword = dto.FmCPPassword;

            _dataService.SaveChanges();

            return(result);
        }
Example #11
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 #12
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 = "Зміна даних користувача пройшла успішно!" }));
        }
        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 prl = _dataService.GetEntity <PrlApplication>(p => p.Id == decision.AppId).SingleOrDefault();

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

            _dataService.Add(decision, isUpdate);
            _limsExchangeService.ExportDecision(decision, isUpdate);

            _dataService.SaveChanges();
        }
Example #14
0
        public override async Task <IActionResult> Edit(Guid id, EDocumentDetailsDTO model)
        {
            if (id != model.Id)
            {
                return(NotFound());
            }

            var fileList = _dataService.GetEntity <FileStore>().Where(x => x.EntityId == id).Select(x => x.EntityId).ToList();
            IEnumerable <BranchListDTO> branchList;

            if (model.AppSort == "AddBranchApplication")
            {
                branchList = await _dataService.GetDtoAsync <BranchListDTO>(x => x.ApplicationId == model.ApplicationId && x.IsFromLicense != true);
            }
            else
            {
                branchList = await _dataService.GetDtoAsync <BranchListDTO>(x => x.ApplicationId == model.ApplicationId);
            }
            if (fileList.Count == 0)
            {
                if (model.AppType == "TRL")
                {
                    ViewBag.selectBranchList = new SelectList(branchList.Select(p => new { p.Id, p.Name }), nameof(BranchListDTO.Id), nameof(BranchListDTO.Name));
                }
                else
                {
                    var multiselectlist = new MultiSelectList(branchList, nameof(BranchListDTO.Id), nameof(BranchListDTO.Name));
                    ViewBag.multiSelectBranchList = multiselectlist;
                }

                ModelState.AddModelError("", "Мае бути додано щонайменьше однин файл");
                //return await Task.FromResult(Json(new { success = false, ErrorMessage = "Мае бути додано щонайменьше однин файл" }));
                return(View(model));
            }

            var branchIds = _dataService.GetEntity <BranchEDocument>().Where(x => x.EDocumentId == id).Select(x => x.BranchId);

            if (model.AppSort != "AddBranchApplication" && (!model.ListOfBranches?.Any() ?? true) && model.AppType != "TRL")
            {
                model.ListOfBranches = branchIds.ToList();

                var multiselectlist = new MultiSelectList(branchList, nameof(BranchListDTO.Id), nameof(BranchListDTO.Name));
                ViewBag.multiSelectBranchList = multiselectlist;
                ModelState.Clear();
                ModelState.AddModelError("ListOfBranches", "Мае бути обрано щонайменьше одне МПД");

                return(View(model));
            }

            if (model.AppType == "TRL" && model.BranchId == null)
            {
                ViewBag.selectBranchList = new SelectList(branchList.Select(p => new { p.Id, p.Name }), nameof(BranchListDTO.Id), nameof(BranchListDTO.Name));
                ModelState.Clear();
                ModelState.AddModelError("BrancheId", "Оберіть МПД");

                return(View(model));
            }
            try
            {
                model.Id = _dataService.Add <EDocument>(model);
                _dataService.SaveChanges();

                var branchContractors =
                    _dataService.GetEntity <BranchEDocument>().Where(x => x.EDocumentId == model.Id).ToList();
                if (branchContractors.Count > 0)
                {
                    branchContractors.ForEach(x => _dataService.Remove(x));
                }

                if (model.AppType == "TRL")
                {
                    _dataService.Add(new BranchEDocument
                    {
                        EDocumentId = model.Id,
                        BranchId    = model.BranchId.Value
                    });
                }
                else
                {
                    model.ListOfBranches?.ForEach(branchId => _dataService.Add(new BranchEDocument
                    {
                        EDocumentId = model.Id,
                        BranchId    = branchId
                    }));
                }
                _dataService.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (await Service.GetListDTO().SingleOrDefaultAsync(x => x.Id == id) == null)
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            var appType = (await _dataService.GetDtoAsync <AppStateDTO>(x => x.Id == model.ApplicationId)).FirstOrDefault()?.AppType;

            switch (appType)
            {
            case "PRL":
                return(RedirectToAction("Details", "Application", new
                {
                    Area = "PRL",
                    Id = model.ApplicationId
                }, "eDocument"));

            case "IML":
                return(RedirectToAction("Details", "Application", new
                {
                    Area = "IML",
                    Id = model.ApplicationId
                }, "eDocument"));

            case "TRL":
                return(RedirectToAction("Details", "Application", new
                {
                    Area = "TRL",
                    Id = model.ApplicationId
                }, "eDocument"));

            default:
                return(NotFound());
            }
        }