//получение снабженцев из ActiveDirectory
        public static List<ProductManager> GetProductManagers()
        {
            //var man = new List<ProductManager>()
            //{
            //   new ProductManager(){Id = "dfsadfs", Name = "Гена", Roles = new List<Role>() { Role.Enter, Role.ProductManager}},
            //   new ProductManager(){Id = "fdbfgbv", Name = "Вася", Roles = new List<Role>() { Role.Enter, Role.ProductManager}},
            //   new ProductManager(){Id = "dfsdfvfdhadfs", Name = "Петр", Roles = new List<Role>() { Role.Enter, Role.ProductManager, Role.Manager}},
            //   new ProductManager(){Id = "dfsdwqedqwefefadfs", Name = "Олег", Roles = new List<Role>() { Role.Enter, Role.ProductManager, Role.Controller}},
            //   new ProductManager(){Id = "df45gfdgsadfs", Name = "Дима", Roles = new List<Role>() { Role.Enter, Role.ProductManager, Role.Operator}},
            //   new ProductManager(){Id = "dfsvdfgdfgdfbadfs", Name = "Alex", Roles = new List<Role>() { Role.Enter, Role.ProductManager}},
            //   new ProductManager(){Id = "khnhbfgbdf", Name = "Stan", Roles = new List<Role>() { Role.Enter, Role.ProductManager}}
            //};
            //man.ForEach((x) => x.ShortName = x.Name);
            //return man;
            using (WindowsImpersonationContextFacade impersonationContext
                = new WindowsImpersonationContextFacade(
                    nc))
            {
                var list = new List<ProductManager>();
                var domain = new PrincipalContext(ContextType.Domain);
                var group = GroupPrincipal.FindByIdentity(domain, IdentityType.Name,
                    _roles.First(x => x.Role == Role.ProductManager).Name);
                if (group != null)
                {
                    var members = group.GetMembers(true);
                    foreach (var principal in members)
                    {
                        var userPrincipal = UserPrincipal.FindByIdentity(domain, principal.Name);
                        if (userPrincipal != null)
                        {
                            var email = userPrincipal.EmailAddress;
                            var name = userPrincipal.DisplayName;
                            var sid = userPrincipal.Sid.Value;
                            var shortName = GetShortName(name);
                            var user = new ProductManager()
                            {
                                Id = sid,
                                Name = name,
                                Email = email,
                                ShortName = shortName,
                                Roles = new List<Role>() {Role.ProductManager}
                            };
                            list.Add(user);
                        }
                    }
                }

                list = list.OrderBy(m => m.ShortName).ToList();
                return list;
            }
        }
        public ActionResult ListOld()
        {
            //получение пользователя и через наличие у него определенных ролей, определяются настройки по
            //функциональности на странице
            var user = GetUser();
            if (user == null || !UserHelper.IsUserAccess(user))
            {
                var dict = new RouteValueDictionary();
                dict.Add("message", "У Вас нет доступа к приложению");
                return RedirectToAction("ErrorPage", "Auth", dict);
            }
            ViewBag.UserName = user.Name;
            var showCalculate = false;
            var showEdit = false;
            var changeTenderStatus = false;
            var filterProduct = string.Empty;
            var filterManager = string.Empty;
            var clickAction = string.Empty;
            var posibleAction = string.Empty;
            var userId = string.Empty;
            var author = string.Empty;
            var reportExcel = false;
            var deleteClaim = "none";
            var newClaim = "true";
            var filterClaimStatus = new List<int>();
            var isController = UserHelper.IsController(user);
            var isTenderStatus = UserHelper.IsTenderStatus(user);
            var isManager = UserHelper.IsManager(user);
            var isProduct = UserHelper.IsProductManager(user);
            var isOperator = UserHelper.IsOperator(user);
            if (isController)
            {
                showCalculate = true;
                showEdit = true;
                changeTenderStatus = true;
                clickAction = "editClaim";
                posibleAction = "all";
                reportExcel = true;
                deleteClaim = "true";
            }
            else
            {
                if (isTenderStatus)
                {
                    changeTenderStatus = true;
                    clickAction = "null";
                    posibleAction = "null";
                    newClaim = "false";
                    if (isOperator || isManager) newClaim = "true";
                }
                if (isManager)
                {
                    showEdit = true;
                    //filterManager = user.Id;
                    clickAction = "editClaim";
                    posibleAction = "editClaim";
                    userId = user.Id;
                    filterClaimStatus.AddRange(new[] { 1, 2, 3, 6, 7 });
                    deleteClaim = "self&manager";
                }
                if (isProduct)
                {
                    showCalculate = true;
                   // filterProduct = user.Id;
                    clickAction = "calculateClaim";
                    posibleAction = (isManager ? "all" : "calculateClaim");
                    userId = user.Id;
                    newClaim = "false";
                    if (isOperator || isManager) newClaim = "true";
                    if (!isManager) filterClaimStatus.AddRange(new[] { 2, 3, 6, 7 });
                }
                if (isOperator)
                {
                    showEdit = true;
                    clickAction = "editClaim";
                    posibleAction = (isProduct ? "all" : "editClaim");
                    author = user.Id;
                    deleteClaim = "self";
                }
            }
            ViewBag.Settings = new
            {
                showCalculate,
                showEdit,
                changeTenderStatus,
                filterProduct,
                filterManager,
                clickAction,
                posibleAction,
                userId,
                filterClaimStatus,
                author,
                reportExcel,
                deleteClaim,
                newClaim
            };
            ViewBag.Error = false.ToString().ToLower();
            ViewBag.ClaimCount = 0;
            try
            {
                //получение инфы по заявкам из БД
                var db = new DbEngine();
                var filter = new FilterTenderClaim()
                {
                    RowCount = 30,
                };
                var subsProduct = new List<KeyValuePair<string, string>>();
                var subsManagers = new List<KeyValuePair<string, string>>();
                if (!string.IsNullOrEmpty(filterManager)) filter.IdManager = filterManager;
                else
                {
                    if (isManager && !isController)
                    {
                        filter.IdManager = user.Id;
                        subsManagers = Employee.GetSubordinates(user.Id).ToList();
                        if (subsManagers.Any())
                        {
                            filter.IdManager = user.Id;// + ","+ String.Join(",", subsManagers);
                            foreach (var sub in subsManagers)
                            {
                                if (sub.Key != null)
                                {
                                    filter.IdManager += "," + sub.Key;
                                }
                            }
                        }
                    }
                }

                if (!string.IsNullOrEmpty(filterProduct)) filter.IdProductManager = filterProduct;
                else
                {

                    if (isProduct && !isController)
                    {
                        filter.IdProductManager = user.Id;
                        subsProduct = Employee.GetSubordinates(user.Id).ToList();
                        if (subsProduct.Any())
                        {
                            filter.IdProductManager = user.Id;// + "," + String.Join(",", subsProduct);
                            foreach (var sub in subsProduct)
                            {
                                if (sub.Key != null)
                                {
                                    filter.IdProductManager += "," + sub.Key;
                                }
                            }
                        }
                    }
                    //filter.IdProductManager = isProduct && !isController
                    //    ? String.Join(",", Employee.GetSubordinates(user.Id))
                    //    : String.Empty;
                }
                if (!string.IsNullOrEmpty(author)) filter.Author = author;
                if (filterClaimStatus.Any()) filter.ClaimStatus = filterClaimStatus;
                var claims = db.FilterTenderClaims(filter);
                //снабженцы и менеджеры из ActiveDirectory
                var prodManSelList = UserHelper.GetProductManagersSelectionList();

                var adProductManagers = new List<ProductManager>();

                adProductManagers = prodManSelList;

                if (!isController && isProduct)
                {
                    var subProds = Employee.GetSubordinateProductManagers(user.Id, subsProduct);
                    if (subProds.Any())
                    {
                        adProductManagers = subProds;
                    }
                    else
                    {
                        var curProd = new ProductManager() {Id = user.Id, ShortName = user.ShortName};
                        adProductManagers = new List<ProductManager>();
                        adProductManagers.Add(curProd);
                    }
                }
                var manSelList = UserHelper.GetManagersSelectionList();

                var managers = new List<Manager>();

                    managers = manSelList;

                if (!isController && isManager)
                {
                    var subMans = Employee.GetSubordinateManagers(user.Id, subsManagers);
                    if (subMans.Any())
                    {
                        managers = subMans;
                    }
                    else
                    {
                        var curMan = new Manager() { Id = user.Id, ShortName = user.ShortName };
                        managers = new List<Manager>();
                        managers.Add(curMan);
                    }
                }

                //var prodManSelList = UserHelper.Get();

                if (claims != null && claims.Any())
                {
                    db.SetProductManagersForClaims(claims);
                    var claimProductManagers = claims.SelectMany(x => x.ProductManagers).ToList();
                    foreach (var claimProductManager in claimProductManagers)
                    {
                        claimProductManager.ShortName = prodManSelList.FirstOrDefault(x=>x.Id== claimProductManager.Id)?.ShortName;
                        //var productUser = UserHelper.GetUserById(claimProductManager.Id);
                        //if (productUser != null)
                        //{
                        //    claimProductManager.Name = productUser.Name;
                        //    claimProductManager.Name = productUser.ShortName;
                        //}
                        //var managerFromAD = adProductManagers.FirstOrDefault(x => x.Id == claimProductManager.Id);
                        //if (managerFromAD != null)
                        //{
                        //    claimProductManager.Name = managerFromAD.Name;
                        //    claimProductManager.ShortName = managerFromAD.ShortName;
                        //}
                    }
                    //var authorsList = UserHelper.GetAuthorsSelectionList();
                    foreach (var claim in claims)
                    {
                        claim.Manager.ShortName = manSelList.FirstOrDefault(x => x.Id == claim.Manager.Id)?.ShortName;
                        //if (manager != null)
                        //{
                        //    claim.Manager.ShortName = manager.ShortName;
                        //}
                        //var auth = authorsList.SingleOrDefault(x => x.Key == claim.Author.Id);
                        claim.Author = UserHelper.GetUserById(claim.Author.Id);//new UserBase() { Id= auth.Key, ShortName = auth.Value};// UserHelper.GetUserById(claim.Author.Id);

                    }
                    db.SetStatisticsForClaims(claims);
                }
                ViewBag.Claims = claims;
                ViewBag.DealTypes = db.LoadDealTypes();
                ViewBag.ClaimStatus = db.LoadClaimStatus();
                ViewBag.ProductManagers = adProductManagers;
                ViewBag.Managers = managers;
                ViewBag.ClaimCount = db.GetCountFilteredTenderClaims(filter);
                ViewBag.TenderStatus = db.LoadTenderStatus();
            }
            catch (Exception ex)
            {
                ViewBag.Error = true.ToString().ToLower();
            }
            return View();
        }
Esempio n. 3
0
 public void SetProductManagersForClaims(List<TenderClaim> claims)
 {
     using (var conn = new SqlConnection(_connectionString))
     {
         var cmd = conn.CreateCommand();
         cmd.CommandType = CommandType.StoredProcedure;
         cmd.CommandText = "GetProductsForClaims";
         cmd.Parameters.AddWithValue("@ids", string.Join(",", claims.Select(x => x.Id)));
         conn.Open();
         var rd = cmd.ExecuteReader();
         if (rd.HasRows)
         {
             while (rd.Read())
             {
                 var idClaim = rd.GetInt32(0);
                 var model = new ProductManager() {Id = rd.GetString(1)};
                 claims.First(x => x.Id == idClaim).ProductManagers.Add(model);
             }
         }
         rd.Dispose();
     }
 }
Esempio n. 4
0
 public List<ProductManager> LoadProductManagersForClaim(int claimId, int version, int[] selIds = null, bool? getActualize = null)
 {
     if (version <= 0)version = 1;
     var list = new List<ProductManager>();
     using (var conn = new SqlConnection(_connectionString))
     {
         var cmd = conn.CreateCommand();
         cmd.CommandType = CommandType.StoredProcedure;
         cmd.CommandText = "LoadProductManagersForClaim";
         cmd.Parameters.AddWithValue("@idClaim", claimId);
         cmd.Parameters.AddWithValue("@version", version);
         cmd.Parameters.AddWithValue("@selIds", selIds != null ? String.Join(",",selIds) : null);
         cmd.Parameters.AddWithValue("@getActualize", getActualize);
         conn.Open();
         var rd = cmd.ExecuteReader();
         if (rd.HasRows)
         {
             while (rd.Read())
             {
                 var model = new ProductManager()
                 {
                     Id = rd.GetString(0)
                 };
                 list.Add(model);
             }
         }
         rd.Dispose();
     }
     return list;
 }
Esempio n. 5
0
        /// <summary>
        /// Возвращает подчиненных владельца id как список продактов
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static List<ProductManager> GetSubordinateProductManagers(string id, List<KeyValuePair<string,string>> list = null)
        {
            var sidList = list ?? GetSubordinates(id);
            var subordinateList = new List<ProductManager>();

            foreach (var item in sidList)
            {
                if (!string.IsNullOrEmpty(item.Key))
                {
                    //var subordinate = UserHelper.GetUserById(sid);
                    var productManagerSubordinate = new ProductManager()
                    {
                        Id = item.Key,
                        //Name = subordinate.Name,
                        ShortName = item.Value,
                        //Roles = new List<Role>() { Role.ProductManager }
                    };
                    subordinateList.Add(productManagerSubordinate);
                }

            }
            subordinateList = subordinateList.OrderBy(m => m.ShortName).ToList();
            return subordinateList;
        }