Exemplo n.º 1
0
        public ResponseAgreement AddRoutingAgreement(RequestAgreement data, string webrootpath)
        {
            var model  = new Agreement();
            var result = new ResponseAgreement();

            try
            {
                var routesfile = File.AppendText(webrootpath + "/agreements");
                var routeline  = "|" + data.Id + "," + data.Name + "," + data.Url + "," + data.OperationService + "," + data.Type + "," + data.Operation;
                routesfile.Write(routeline);
                routesfile.Close();

                result.Code = 200;
                result.Data = new Agreement()
                {
                    Id               = data.Id,
                    Name             = data.Name,
                    Type             = data.Type,
                    OperationService = data.OperationService,
                    Operation        = data.Operation,
                    Url              = data.Url,
                };


                result.Message = "OK";
            }
            catch (Exception ex)
            {
                result.Code    = 500;
                result.Message = ex.Message;
                result.Data    = null;
            }

            return(result);
        }
Exemplo n.º 2
0
        public RequestAgreement ExcludeAgreementor(RequestAgreement agreement)
        {
            var user = _databaseContext.AclUsers.FirstOrDefault(r => !r.Deleted && (r.IdUser == agreement.IdUser));

            agreement.User = user;
            return(UpdateRequestAgreement(agreement));
        }
Exemplo n.º 3
0
        public ResponseAgreement AddRoutingAgreement(RequestAgreement data, string webrootpath)
        {
            var context  = _httpContext.RequestServices.GetService(typeof(RoutingDao)) as RoutingDao;
            var response = context.AddRoutingAgreement(data, webrootpath);

            return(response);
        }
Exemplo n.º 4
0
        public RequestAgreement AddAdditionalAgreement(RequestAgreement agreement)
        {
            var department = _databaseContext.Departments.FirstOrDefault(
                r => !r.Deleted && r.IdParentDepartment == null &&
                r.Name.ToLower() == agreement.User.Department.Name.ToLower());
            var idDepartment = department == null ? 24 : department.IdDepartment;

            agreement.User.Department   = null;
            agreement.User.IdDepartment = idDepartment;
            agreement.User.Roles        = agreement.User.Roles.Select(
                r => _databaseContext.AclRoles.Find(r.IdRole)).ToList();
            var user = _databaseContext.AclUsers.FirstOrDefault(r => !r.Deleted &&
                                                                (r.Login.ToLower() == agreement.User.Login.ToLower())) ??
                       _databaseContext.AclUsers.Add(agreement.User);

            foreach (var aclRole in agreement.User.Roles)
            {
                if (user.Roles.All(r => r.IdRole != aclRole.IdRole))
                {
                    user.Roles.Add(aclRole);
                }
            }
            agreement.User   = user;
            agreement.IdUser = user.IdUser;
            return(UpdateRequestAgreement(agreement, true));
        }
Exemplo n.º 5
0
        public RequestAgreement UpdateRequestAgreement(RequestAgreement agreement, bool updateSendInfo = false)
        {
            var reqAgreement = _databaseContext.RequestAgreements.
                               FirstOrDefault(r => r.IdUser == agreement.User.IdUser &&
                                              r.IdRequest == agreement.IdRequest &&
                                              r.IdAgreementType == agreement.IdAgreementType);

            if (reqAgreement == null)
            {
                return(_databaseContext.RequestAgreements.Add(agreement));
            }
            agreement.IdAgreementType    = reqAgreement.IdAgreementType;
            agreement.IdRequestAgreement = reqAgreement.IdRequestAgreement;
            if (!updateSendInfo)
            {
                agreement.SendDate        = reqAgreement.SendDate;
                agreement.SendDescription = reqAgreement.SendDescription;
            }
            _databaseContext.Entry(reqAgreement).CurrentValues.SetValues(agreement);
            return(reqAgreement);
        }
Exemplo n.º 6
0
        public ResponseAgreement AddRoutingAgreement([FromBody] RequestAgreement data)
        {
            var result          = new ResponseAgreement();
            var validateRequest = SchemaEngine.Validate <RequestAgreement>(data, reqAgreementSchema);

            if (validateRequest)
            {
                var serv = new RoutingBusiness(HttpContext);
                result = serv.AddRoutingAgreement(data, webRootPath);

                if (result.Code == 200)
                {
                    var validate = SchemaEngine.Validate <ResponseAgreement>(result, respAgreementSchema);

                    if (!validate)
                    {
                        result.Code    = 500;
                        result.Message = "Invalid result data schema";
                        result.Data    = null;

                        return(result);
                    }
                }
                else
                {
                    return(result);
                }

                return(result);
            }
            else
            {
                result.Code    = 500;
                result.Message = "Invalid params schema";
                result.Data    = null;

                return(result);
            }
        }
Exemplo n.º 7
0
        public void AddCooordinator(int idRequest, Coordinator coordinator, string sendDescription)
        {
            var agreement = new RequestAgreement
            {
                IdRequest        = idRequest,
                IdAgreementType  = 2,
                IdAgreementState = 1,
                SendDate         = DateTime.Now,
                SendDescription  = sendDescription,
                User             = new AclUser
                {
                    Login      = coordinator.Login,
                    Snp        = coordinator.Snp,
                    Email      = coordinator.Email,
                    Phone      = coordinator.Phone,
                    Department = new Department
                    {
                        IdParentDepartment = null,
                        Name = coordinator.Department
                    },
                    Roles = new List <Domain.Entities.AclRole>
                    {
                        new Domain.Entities.AclRole
                        {
                            IdRole = 8
                        }
                    }
                }
            };
            var requestState = new RequestState
            {
                IdRequest          = idRequest,
                IdRequestStateType = 1,
                Date = DateTime.Now
            };

            RequestsRepository.AddRequestState(requestState, false);
            RequestsRepository.AddAdditionalAgreement(agreement);
        }
Exemplo n.º 8
0
        public void ExcludeAgreementor(int idRequest, int idUser, int idRequestAgreementType)
        {
            var requestState = new RequestState
            {
                IdRequest          = idRequest,
                IdRequestStateType = 2,
                Date = DateTime.Now
            };

            var agreement = new RequestAgreement
            {
                IdRequest        = idRequest,
                IdUser           = idUser,
                IdAgreementState = 4,
                IdAgreementType  = idRequestAgreementType
            };

            RequestsRepository.ExcludeAgreementor(agreement);
            if (!NeedAdditionalAgreements(idRequest, agreement))
            {
                RequestsRepository.AddRequestState(requestState, false);
            }
        }
 public bool CanViewAgreementSendDescription(RequestAgreement agreement)
 {
     return(InRole(new [] { AclRole.Administrator, AclRole.Dispatcher, AclRole.Registrar }) ||
            (InRole(AclRole.Coordinator) && agreement.IdUser == GetUserInfo().IdUser));
 }
Exemplo n.º 10
0
 private bool NeedAdditionalAgreements(int idRequest, RequestAgreement newAgreement)
 {
     return(GetWaitAgreementUsers(idRequest,
                                  GetRequestAgreements(idRequest).ToList().Concat(new[] { newAgreement }).ToList()).Any());
 }
Exemplo n.º 11
0
        public void SetRequestState(int idRequest, int idRequestStateType, string reason)
        {
            var userInfo = RequestSecurityService.GetUserInfo();

            if (userInfo == null)
            {
                throw new DbUpdateException("Неизвестный пользователь");
            }
            var requestState = new RequestState
            {
                IdRequest          = idRequest,
                IdRequestStateType = idRequestStateType,
                Date = DateTime.Now
            };
            var waitAgreementUsers = GetWaitAgreementUsers(idRequest,
                                                           GetRequestAgreements(idRequest).ToList());
            var agreement = new RequestAgreement
            {
                IdRequest            = idRequest,
                User                 = userInfo,
                IdUser               = userInfo.IdUser,
                IdAgreementState     = idRequestStateType == 2 ? 2 : 3,
                IdAgreementType      = 1,
                AgreementDescription = reason,
                AgreementDate        = DateTime.Now
            };

            switch (idRequestStateType)
            {
            case 1:
                RequestsRepository.AddRequestState(requestState, true);
                break;

            case 2:
                if (RequestSecurityService.InRole(AclRole.Coordinator) &&
                    waitAgreementUsers.Any(r =>
                                           r.RequestAgreements.Any(
                                               ra => ra.IdRequest == idRequest &&
                                               ra.IdUser == userInfo.IdUser &&
                                               ra.IdAgreementType == 2) && r.IdUser == userInfo.IdUser))
                {
                    agreement.IdAgreementType = 2;
                }
                else
                if (RequestSecurityService.InRole(AclRole.Administrator))
                {
                    RequestsRepository.AddRequestState(requestState, false);
                    break;
                }
                RequestsRepository.UpdateRequestAgreement(agreement);
                if (!NeedAdditionalAgreements(idRequest, agreement))
                {
                    RequestsRepository.AddRequestState(requestState, false);
                }
                break;

            case 3:
                RequestsRepository.AddRequestState(requestState, false);
                break;

            case 5:
                if (RequestSecurityService.InRole(AclRole.Coordinator) &&
                    waitAgreementUsers.Any(r =>
                                           r.RequestAgreements.Any(
                                               ra => ra.IdRequest == idRequest &&
                                               ra.IdUser == userInfo.IdUser &&
                                               ra.IdAgreementType == 2) && r.IdUser == userInfo.IdUser))
                {
                    agreement.IdAgreementType       = 2;
                    requestState.IdRequestStateType = 2;
                    RequestsRepository.UpdateRequestAgreement(agreement);
                    if (!NeedAdditionalAgreements(idRequest, agreement))
                    {
                        RequestsRepository.AddRequestState(requestState, false);
                    }
                }
                else
                {
                    RequestsRepository.UpdateRequestAgreement(agreement);
                    RequestsRepository.AddRequestState(requestState, false);
                }
                break;

            case 4:
                RequestsRepository.AddRequestState(requestState, false);
                break;
            }
        }