コード例 #1
0
        /// <summary>
        /// 添加负责人
        /// </summary>
        /// <param name="model"></param>
        /// <param name="errors"></param>
        /// <returns></returns>
        public bool AddManager(ManagerAccount model, ref ValidationErrors errors)
        {
            try
            {
                Manager entity      = ManagerRepository.GetManagerById(model.ManagerId);
                int     channelType = Convert.ToInt32(Enum.Parse(typeof(ChannelType), model.ChannelTypeStr));
                if (entity != null)
                {
                    errors.Add(Suggestion.ExistUser);
                    return(false);
                }
                if (channelType != 4)
                {
                    entity = new Manager
                    {
                        ManagerId      = model.ManagerId,
                        ManagerName    = model.ManagerName,
                        ManagerEmail   = model.ManagerEmail,
                        MobilePhone    = model.MobilePhone,
                        IdCardNo       = model.IdCardNo,
                        ChannelType    = Convert.ToInt32(Enum.Parse(typeof(ChannelType), model.ChannelTypeStr)),
                        ChannelId      = model.ChannelId,
                        ShareChannelId = 1,
                        CId            = model.CityId,
                        CreatedTime    = DateTime.Now,
                        ModifiedTime   = null,
                        IsActive       = Convert.ToInt32(Enum.Parse(typeof(Status), model.IsActiveStr))
                    };

                    if (ManagerRepository.AddManager(entity) == 1)
                    {
                        return(true);
                    }
                    errors.Add(Suggestion.AddNotShareUserFailed);
                    return(false);
                }
                else
                {
                    var shareChannel = new ShareChannel
                    {
                        ShareChannelId = model.ManagerId,
                        ChannelName    = model.ShareChannelName + "-" + model.ManagerId,
                        Rank           = 1,
                        ChannelType    = Convert.ToInt32(Enum.Parse(typeof(ChannelType), model.ChannelTypeStr)),
                        ParentId       = 1,
                        Sort           = 1,
                        CreatedTime    = DateTime.Now,
                        ModifiedTime   = null,
                        IsActive       = 1
                    };

                    //var flag = ShareChannelRepository.AddShareChannel(shareChannel);
                    //var flag = ShareChannelRepository.AddShareChannelByfk("ShareChannel", shareChannel);

                    //if (flag > 0)
                    //{
                    entity = new Manager
                    {
                        ManagerId    = model.ManagerId,
                        ManagerName  = model.ManagerName,
                        ManagerEmail = model.ManagerEmail,
                        MobilePhone  = model.MobilePhone,
                        IdCardNo     = model.IdCardNo,
                        ChannelType  = Convert.ToInt32(Enum.Parse(typeof(ChannelType), model.ChannelTypeStr)),
                        ChannelId    = 1,
                        ShareChannel = shareChannel,
                        CId          = model.CityId,
                        CreatedTime  = DateTime.Now,
                        ModifiedTime = null,
                        IsActive     = Convert.ToInt32(Enum.Parse(typeof(Status), model.IsActiveStr))
                    };

                    var flag = ManagerRepository.AddManager(entity);
                    //var flag = ManagerRepository.AddManagerByfk("Managers", entity);

                    if (flag > 0)
                    {
                        return(true);
                    }
                    errors.Add(Suggestion.AddShareUserFailed);
                    return(false);
                    //}
                    //errors.Add(Suggestion.AddShareUserChannelFailed);
                    //return false;
                }
            }
            catch (Exception ex)
            {
                errors.Add(ex.Message);
                return(false);
            }
        }