コード例 #1
0
        public static string RequstsToSignCount(int empId)
        {
            transportEntities _db = new transportEntities();
            var rqsts             = _db.Requests.Where(rq => (rq.ApproverEmployeeId == empId && (rq.Status == 0) && (rq.IsDeleted != true))).ToList();

            return(rqsts.Count.ToString());
        }
コード例 #2
0
        public string _FindCustomers(bool withInvoice)
        {
            var _db       = new transportEntities();
            var customers = new List <string>();

            _db.v_RequestCustomers.Where(customer => customer.SHZ == (withInvoice ? "Д3" : "Д2"))
            .OrderBy(c => c.CustomerName).ToList()
            .ForEach(
                c =>
                customers.Add(String.Format(@"<option value=""{0}"">{1}</option>", c.CustomerId,
                                            "[" + c.SHZ + "] " + c.CustomerName.Replace("Договор 2", "").Replace("Договор 3", ""))));
            return(@"<option value=""0""></option>" + String.Join("", customers.ToArray()));
        }
コード例 #3
0
        public string _FindDirection(int agreementId, int departmentGroupId)
        {
            var _db        = new transportEntities();
            var directions = new List <string>();

            //var AgreementId = withInvoice ? 3 : 2;

            _db.view_ServiceDirection.Where(
                x => x.AgreementId == agreementId && x.ServiceDepartmentGroupId == departmentGroupId)
            .ToList()
            .ForEach(
                d =>
                directions.Add(String.Format(@"<option value=""{0}"">{1}</option>", d.DirectionId,
                                             d.DirectionName)));

            return(@"<option value=""0""></option>" + String.Join("", directions.ToArray()));
        }
コード例 #4
0
        public string _FindPurpose(int agreementId, int departmentGroupId)
        {
            var _db      = new transportEntities();
            var purposes = new List <string>();

            //var AgreementId = withInvoice ? 3 : 2;

            if (departmentGroupId != 0)
            {
                _db.view_ServicePurpose.Where(
                    x =>
                    x.AgreementId == agreementId &&
                    (x.ServiceDepartmentGroupId == null || x.ServiceDepartmentGroupId == departmentGroupId))
                .ToList()
                .ForEach(
                    d =>
                    purposes.Add(String.Format(@"<option value=""{0}"">{1}</option>", d.AgreementPurposeId,
                                               d.PurposeName)));
            }
            return(@"<option value=""0""></option>" + String.Join("", purposes.ToArray()));
        }
コード例 #5
0
        /// <summary>
        /// Is current user has permissions to approve transport requests
        /// </summary>
        /// <param name="identity"></param>
        /// <returns>Tuple where Item1 - EmloyeeId, Item2 - is this user approver </returns>
        public static Tuple <int, bool> IsApprover(string identity)
        {
            var _db = new transportEntities();

            if (String.IsNullOrEmpty(identity))
            {
                return(new Tuple <int, bool>(10, true));
            }

            var      login    = Login(identity);
            Employee employee = _db.Employees.SingleOrDefault(e => e.Login == login);

            if (employee == null)
            {
                var context = new PrincipalContext(ContextType.Domain, "lan.naftan.by");
                if (identity.Substring(0, 7).ToLower() == "polymir") //If user from Polymir than MAGIC
                {
                    //парсить кусок логина на предмет табельного номера
                    string tabN = identity.Substring(9, identity.Length - 9);
                    int    n    = 0;
                    for (int i = 0; i < tabN.Length; i++)
                    {
                        if (tabN.Substring(i, 1) != "0")
                        {
                            n = i;
                            break;
                        }
                    }
                    tabN     = tabN.Substring(n, tabN.Length - n); //предполагаемый табельный номер
                    employee = _db.Employees.SingleOrDefault(e => e.EmployeeNumber == tabN);
                }
                else //User from Naftan, do search in AD
                {
                    string sIdMan = String.Empty;
                    int    idMan  = 0;
                    using (context)
                    {
                        var principal = UserPrincipal.FindByIdentity(context, identity);
                        sIdMan = principal.EmployeeId;
                    }
                    Int32.TryParse(sIdMan, out idMan);
                    employee = _db.Employees.SingleOrDefault(e => e.id_men == idMan);

                    if (employee == null)
                    //Если полимировец с логином из домена LAN
                    {
                        //парсить кусок логина на предмет табельного номера
                        string tabN = identity.Substring(5, identity.Length - 5);
                        int    n    = 0;
                        for (int i = 0; i < tabN.Length; i++)
                        {
                            if (tabN.Substring(i, 1) != "0")
                            {
                                n = i;
                                break;
                            }
                        }
                        tabN     = tabN.Substring(n, tabN.Length - n); //предполагаемый табельный номер
                        employee = _db.Employees.SingleOrDefault(e => e.EmployeeNumber == tabN);
                    }
                }

                if (employee != null)
                {
                    employee.Login = login;
                    _db.SaveChanges();
                }
            }

            if (employee == null)
            {
                return(Tuple.Create(0, false));
            }

            bool isApprover = _db.RequestApprovers.Any(ap => ap.EmployeeId == employee.EmployeeId);

            return(Tuple.Create(employee.EmployeeId, isApprover));
        }
コード例 #6
0
 public RequestPassengerViewModel()
 {
     transportEntities _db = new transportEntities();
 }