Example #1
0
 public Employee Get(string adSid)
 {
     bool userCanViewHiddenEmps = AdHelper.UserInGroup(GetCurUser().User, AdGroup.PersonalManager, AdGroup.SuperAdmin);
     var emp = new Employee(adSid);
     if (emp.IsHidden && !userCanViewHiddenEmps) return new Employee();
     return emp;
 }
 public Employee Get(string adSid, bool showHidden = false)
 {
     bool userCanViewHiddenEmps = showHidden || GetCurUser().HasAccess(AdGroup.PersonalManager, AdGroup.SuperAdmin);
     var emp = new Employee(adSid);
     if (emp.IsHidden && !userCanViewHiddenEmps) return new Employee();
     return emp;
 }
Example #3
0
 private void FillSelf(DataRow row)
 {
     Manager = new Employee() { AdSid = Db.DbHelper.GetValueString(row, "Manager") };
     State = new TenderState() { Id = Db.DbHelper.GetValueIntOrDefault(row, "id_state"), Name = Db.DbHelper.GetValueString(row, "state_name") };
     PositionCount = Db.DbHelper.GetValueIntOrDefault(row, "position_count"); //Db.DbHelper.GetValueInt(row["position_count"]);
     CalcCount = Db.DbHelper.GetValueIntOrDefault(row, "calc_count");
 }
Example #4
0
        public IEnumerable<Document> GetMyList()
        {
            var emp = new Employee(GetCurUser().Sid);
            int idDepartment = emp.Department.Id;
            int idPosition = emp.Position.Id;
            int idEmployee = emp.Id;

            return Document.GetList(idDepartment, idPosition, idEmployee);
        }
Example #5
0
        public static IEnumerable<Employee> GetStNewbieList(int? idDepartment = null, bool userCanViewHiddenEmps = false)
        {
            SqlParameter pIdEmpState = new SqlParameter() { ParameterName = "id_emp_state", SqlValue = EmpState.GetNewbieState().Id, SqlDbType = SqlDbType.Int };
            SqlParameter pIdDepartment = new SqlParameter() { ParameterName = "id_department", SqlValue = idDepartment, SqlDbType = SqlDbType.Int };
            var dt = Db.Stuff.ExecuteQueryStoredProcedure("get_other_employee_list", pIdEmpState, pIdDepartment);

            var lst = new List<Employee>();

            foreach (DataRow row in dt.Rows)
            {
                var emp = new Employee(row);
                if (emp.IsHidden && !userCanViewHiddenEmps) continue;
                lst.Add(emp);
            }

            return lst;
        }
Example #6
0
        public static IEnumerable<Employee> GetNewbieList(DateTime dateCreate)
        {
            SqlParameter pDateCreate = new SqlParameter() { ParameterName = "date_came", SqlValue = dateCreate, SqlDbType = SqlDbType.Date };
            var dt = Db.Stuff.ExecuteQueryStoredProcedure("get_employees_newbie", pDateCreate);

            var lst = new List<Employee>();

            foreach (DataRow row in dt.Rows)
            {
                var emp = new Employee(row);
                lst.Add(emp);
            }

            return lst;
        }
Example #7
0
        public static IEnumerable<Employee> GetMonthBirthdayList(int month)
        {
            SqlParameter pMonth = new SqlParameter() { ParameterName = "month", SqlValue = month, SqlDbType = SqlDbType.Int };
            var dt = Db.Stuff.ExecuteQueryStoredProcedure("get_employees_birthday", pMonth);

            var lst = new List<Employee>();

            foreach (DataRow row in dt.Rows)
            {
                var emp = new Employee(row);
                lst.Add(emp);
            }

            return lst;
        }
Example #8
0
        public static IEnumerable<Employee> GetList(int? idDepartment = null, bool getPhoto = false, int? idCity = null, int? idManager = null, bool userCanViewHiddenEmps = false, bool showHidden = true, int? idBudget = null)
        {
            SqlParameter pIdDepartment = new SqlParameter() { ParameterName = "id_department", SqlValue = idDepartment, SqlDbType = SqlDbType.Int };
            SqlParameter pGetPhoto = new SqlParameter() { ParameterName = "get_photo", SqlValue = getPhoto, SqlDbType = SqlDbType.Bit };
            SqlParameter pIdCity = new SqlParameter() { ParameterName = "id_city", SqlValue = idCity, SqlDbType = SqlDbType.Int };
            SqlParameter pIdManager = new SqlParameter() { ParameterName = "id_manager", SqlValue = idManager, SqlDbType = SqlDbType.Int };
            SqlParameter pIdBudget = new SqlParameter() { ParameterName = "id_budget", SqlValue = idBudget, SqlDbType = SqlDbType.Int };
            //if (sysNamePositions == null) sysNamePositions = new[] {""};
            //SqlParameter pSysNamePositions = new SqlParameter() { ParameterName = "lst_pos_sys_name", SqlValue = String.Join(",", sysNamePositions), SqlDbType = SqlDbType.NVarChar };

            var dt = Db.Stuff.ExecuteQueryStoredProcedure("get_employee_list", pIdDepartment, pGetPhoto, pIdCity, pIdManager, pIdBudget);

            var lst = new List<Employee>();

            foreach (DataRow row in dt.Rows)
            {
                var emp = new Employee(row);
                if (emp.IsHidden && (!userCanViewHiddenEmps || !showHidden)) continue;
                lst.Add(emp);
            }

            return lst;
        }
Example #9
0
 private void FillSelf(DataRow row)
 {
     Id = Db.DbHelper.GetValueInt(row["id"]);
     Question = new Question() { Id = Db.DbHelper.GetValueInt(row["id_question"]) };
     string adSid = row["user_sid"].ToString();
     User = new Employee(adSid);
     Descr = row["descr"].ToString();
     QuePosAnswers = QuePosAnswer.GetList(Id);
 }
Example #10
0
 private static void SendQuestionAnsweredNote(int id, bool isTest = false)
 {
     string body = String.Format("<p>Добрый день!</p><p>Получен ответ на ваш вопрос в системе СпецРасчет.</p>" +
                                 "<p>Ссылка: <a href='{0}'>{0}</a></p>", Settings.SpeCalc.Url + "/Question/Index/" + id);
     var recipients = new Employee(new Question(id).Manager.AdSid).Email;
     MessageHelper.SendMailSmtp("Ответ на вопрос в системе СпецРасчет", body, true, recipients, null, Settings.SpeCalc.DefaultMailFrom, isTest:isTest);
 }
Example #11
0
        public HttpResponseMessage Save(Employee emp)
        {
            HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.Created);

            try
            {
                emp.CurUserAdSid = GetCurUser().Sid;
                emp.Save();
                response.Content = new StringContent(String.Format("{{\"id\":{0}}}", emp.Id));
            }
            catch (Exception ex)
            {
                response = new HttpResponseMessage(HttpStatusCode.OK);
                response.Content = new StringContent(MessageHelper.ConfigureExceptionMessage(ex));
            }
            return response;
        }
Example #12
0
 public bool IsChief(string sid)
 {
     bool result = new Employee(sid).IsChief;
     return result;
 }
Example #13
0
        public HttpResponseMessage GetPhoto(int id)
        {
            HttpResponseMessage httpResponseMessage = new HttpResponseMessage();

            var emp = new Employee(id, true);
            if (emp.Photo == null || (emp.Photo != null && emp.Photo.Length == 0))
            {
                if (emp.Male)
                {
                    emp.Photo = File.ReadAllBytes(System.Web.Hosting.HostingEnvironment.MapPath("~/Content/images/no_photo_male.jpg"));
                }
                else { emp.Photo = File.ReadAllBytes(System.Web.Hosting.HostingEnvironment.MapPath("~/Content/images/no_photo_female.png")); }
            }

            httpResponseMessage.Content = new ByteArrayContent(emp.Photo);

            httpResponseMessage.Content.Headers.ContentType = new MediaTypeHeaderValue("image/gif");
            httpResponseMessage.StatusCode = HttpStatusCode.OK;

            return httpResponseMessage;
        }
Example #14
0
        //public static void GetEmployeeManager(Employee emp, out string managerUsername)
        //{
        //    managerUsername = String.Empty;
        //    if (emp.Department == null) return;
        //    if (!Department.CheckUserIsChief(emp.Department.Id, emp.Id))
        //    {
        //        managerUsername = emp.Manager != null ? GetLoginFromEmail(emp.Manager.Email) : String.Empty;
        //    }
        //    if (String.IsNullOrEmpty(managerUsername))
        //    {
        //        Department currDep = new Department(emp.Department.Id);
        //        GetParentDepChief(currDep, out managerUsername);
        //    }
        //}
        //public static void GetParentDepChief(Department dep, out string managerUsername)
        //{
        //    managerUsername = String.Empty;
        //    if (dep.ParentDepartment != null && dep.ParentDepartment.Id > 0)
        //    {
        //        var parentDep = new Department(dep.ParentDepartment.Id);
        //        var overManager = new Employee(parentDep.Chief.Id);
        //        managerUsername = GetLoginFromEmail(overManager.Email);
        //        if (String.IsNullOrEmpty(managerUsername))
        //        {
        //            GetParentDepChief(parentDep, out managerUsername);
        //        }
        //    }
        //}
        public static string SaveUser(Employee emp)
        {
            if (!emp.HasAdAccount) return String.Empty;
            using (WindowsImpersonationContextFacade impersonationContext
                = new WindowsImpersonationContextFacade(
                    nc))
            {
                string username = String.IsNullOrEmpty(emp.AdLogin) ? GetLoginFromEmail(emp.Email) : StringHelper.Trim(emp.AdLogin);

                if (String.IsNullOrEmpty(username.Trim())) return string.Empty;
                string mail = StringHelper.Trim(emp.Email);
                string fullName = StringHelper.Trim(emp.FullName);
                string surname = StringHelper.Trim(emp.Surname);
                string name = StringHelper.Trim(emp.Name);
                string position = emp.Position != null ? emp.Position.Id > 0 && String.IsNullOrEmpty(emp.Position.Name) ? new Position(emp.Position.Id).Name : emp.Position.Name : String.Empty;
                string workNum = StringHelper.Trim(emp.WorkNum);
                string mobilNum = StringHelper.Trim(emp.MobilNum);
                string city = emp.City != null ? StringHelper.Trim(emp.City.Name) : String.Empty;
                string org = emp.Organization != null ? emp.Organization.Id > 0 && String.IsNullOrEmpty(emp.Organization.Name) ? new Organization(emp.Organization.Id).Name : emp.Organization.Name : String.Empty;
                string dep = emp.Department != null ? emp.Department.Id > 0 && String.IsNullOrEmpty(emp.Department.Name) ? new Department(emp.Department.Id).Name : emp.Department.Name : String.Empty;
                var photo = emp.Photo != null && emp.Photo.Length > 0 ? emp.Photo : null;
                Employee manager = new Employee(emp.Manager.Id);
                string managerUsername = String.IsNullOrEmpty(manager.AdLogin)
                    ? GetLoginFromEmail(manager.Email)
                    : manager.AdLogin;
                //GetEmployeeManager(emp, out managerUsername);
                string managerName = String.Empty;
                bool userIsExist = false;

                DirectoryEntry directoryEntry = new DirectoryEntry(DomainPath);

                using (directoryEntry)
                {
                    //Если пользователь существует
                    DirectorySearcher search = new DirectorySearcher(directoryEntry);
                    search.Filter = String.Format("(&(objectClass=user)(sAMAccountName={0}))", username);
                    SearchResult resultUser = search.FindOne();
                    userIsExist = resultUser != null && resultUser.Properties.Contains("sAMAccountName");
                }

                if (!String.IsNullOrEmpty(managerUsername.Trim()))
                {
                    using (directoryEntry)
                    {
                        DirectorySearcher search = new DirectorySearcher(directoryEntry);
                        search.Filter = String.Format("(&(objectClass=user)(sAMAccountName={0}))", managerUsername);
                        search.PropertiesToLoad.Add("DistinguishedName");
                        SearchResult resultManager = search.FindOne();
                        if (resultManager != null)
                            managerName = (string)resultManager.Properties["DistinguishedName"][0];
                    }
                }

                if (!userIsExist)
                {
                    //Создаем аккаунт в AD
                    using (
                        var pc = new PrincipalContext(ContextType.Domain, "UN1T", "OU=Users,OU=UNIT,DC=UN1T,DC=GROUP"))
                    {
                        using (var up = new UserPrincipal(pc))
                        {
                            up.SamAccountName = username;
                            up.UserPrincipalName = username + "@unitgroup.ru";
                            up.SetPassword("z-123456");
                            up.Enabled = true;
                            up.ExpirePasswordNow();

                            try
                            {
                                up.Save();
                            }
                            catch (PrincipalOperationException ex)
                            {

                            }
                        }
                    }

                    //Создаем аккаунт в Exchange

                    //Создаем аккаунт в Lync
                }

                //Еще один путь для изменения параметров
                //if (up.GetUnderlyingObjectType() == typeof(DirectoryEntry))
                //{
                //    DirectoryEntry entry = (DirectoryEntry)up.GetUnderlyingObject();
                //        entry.Properties["streetAddress"].Value = address;

                //        entry.CommitChanges();

                //}

                directoryEntry = new DirectoryEntry(DomainPath);
                using (directoryEntry)
                {

                    //DirectoryEntry user = directoryEntry.Children.Add("CN=" + username, "user");
                    DirectorySearcher search = new DirectorySearcher(directoryEntry);
                    search.Filter = String.Format("(&(objectClass=user)(sAMAccountName={0}))", username);
                    search.PropertiesToLoad.Add("objectsid");
                    search.PropertiesToLoad.Add("samaccountname");
                    search.PropertiesToLoad.Add("userPrincipalName");
                    search.PropertiesToLoad.Add("mail");
                    search.PropertiesToLoad.Add("usergroup");
                    search.PropertiesToLoad.Add("displayname");
                    search.PropertiesToLoad.Add("givenName");
                    search.PropertiesToLoad.Add("sn");
                    search.PropertiesToLoad.Add("title");
                    search.PropertiesToLoad.Add("telephonenumber");
                    search.PropertiesToLoad.Add("homephone");
                    search.PropertiesToLoad.Add("mobile");
                    search.PropertiesToLoad.Add("manager");
                    search.PropertiesToLoad.Add("l");
                    search.PropertiesToLoad.Add("company");
                    search.PropertiesToLoad.Add("department");
                    //search.PropertiesToLoad.Add("modifyTimeStamp");
                    //search.PropertiesToLoad.Add("whenChanged");
                    //search.PropertiesToLoad.Add("whenCreated");

                    SearchResult resultUser = search.FindOne();

                    if (resultUser == null) return String.Empty;

                    //string s = resultUser.Properties["modifyTimeStamp"][0].ToString();
                    //string s1 = resultUser.Properties["whenChanged"][0].ToString();
                    //string s2 = resultUser.Properties["whenCreated"][0].ToString();
                    //DateTime d = DateTime.FromFileTime((Int64)resultUser.Properties["uSNChanged"][0]);

                    DirectoryEntry user = resultUser.GetDirectoryEntry();
                    //user.Properties["sAMAccountName"].Value =username;
                    //user.Properties["userPrincipalName"].Value =username;
                    SetProp(ref user, ref resultUser, "mail", mail);
                    SetProp(ref user, ref resultUser, "displayname", fullName);
                    SetProp(ref user, ref resultUser, "givenName", surname);
                    SetProp(ref user, ref resultUser, "sn", name);
                    SetProp(ref user, ref resultUser, "title", position);
                    SetProp(ref user, ref resultUser, "telephonenumber", workNum);
                    SetProp(ref user, ref resultUser, "mobile", mobilNum);
                    SetProp(ref user, ref resultUser, "l", city);
                    SetProp(ref user, ref resultUser, "company", org);
                    SetProp(ref user, ref resultUser, "department", dep);
                    SetProp(ref user, ref resultUser, "manager", managerName);
                    user.Properties["jpegPhoto"].Clear();
                    SetProp(ref user, ref resultUser, "jpegPhoto", photo);
                    //using (WindowsImpersonationContextFacade impersonationContext= new WindowsImpersonationContextFacade(nc))
                    //{
                    user.CommitChanges();
                    //}
                    SecurityIdentifier sid = new SecurityIdentifier((byte[])resultUser.Properties["objectsid"][0],
                        0);

                    return sid.Value;

                }
                return String.Empty;
            }
        }
Example #15
0
        public static MailAddress[] GetRecipientsFromAdGroup(AdGroup group)
        {
            var list = new List<MailAddress>();
            using (WindowsImpersonationContextFacade impersonationContext
                = new WindowsImpersonationContextFacade(
                    nc))
            {
                string sid = AdUserGroup.GetSidByAdGroup(group);
                PrincipalContext ctx = new PrincipalContext(ContextType.Domain);
                GroupPrincipal grp = GroupPrincipal.FindByIdentity(ctx, IdentityType.Sid, sid);

                if (grp != null)
                {
                    foreach (Principal p in grp.GetMembers(true))
                    {
                        string email = new Employee(p.Sid.Value).Email;
                        if (String.IsNullOrEmpty(email)) continue;
                        list.Add(new MailAddress(email));
                    }
                    grp.Dispose();
                }

                ctx.Dispose();

                return list.ToArray();
            }
        }
Example #16
0
        internal void Save(bool isRefill = false, bool isAdSync = false)
        {
            if (HasAdAccount && String.IsNullOrEmpty(Email)) throw new ArgumentException("Невозможно сохранить запись о сотруднике! Заполните поле Email!");

            bool isEdit = (Id == 0);
            if (String.IsNullOrEmpty(AdSid))
            {
                AdSid = "";
            }
            if (Creator == null) Creator = new Employee();
            if (Position == null) Position = new Position();
            if (Department == null) Department = new Department();
            if (Organization == null) Organization = new Organization();
            if (City == null) City = new City();
            if (PositionOrg == null) PositionOrg = new Position();
            if (Manager == null) Manager = new Employee();
            if (Department.Id != 0)
            {
                Department = new Department(Department.Id);
                if (Id != Department.Chief.Id)
                {
                    Manager = new Employee() { Id = GetManagerId(Department.Id) };
                }
                else
                {
                    var parDep = new Department(Department.Id);
                    if (parDep.ParentDepartment != null && parDep.ParentDepartment.Id > 0)
                    {
                        Manager = new Employee() { Id = GetManagerId(parDep.ParentDepartment.Id) };
                    }
                }
            }

            if (EmpState == null) EmpState = EmpState.GetNewbieState();

            Name = StringHelper.Trim(Name);
            Surname = StringHelper.Trim(Surname);
            Patronymic = StringHelper.Trim(Patronymic);

            FullName = $"{Surname} {Name} {Patronymic}";
            DisplayName =
                $"{Surname} {(!String.IsNullOrEmpty(Name) ? Name[0] + "." : String.Empty)}{(!String.IsNullOrEmpty(Patronymic) ? Patronymic[0] + "." : String.Empty)}";
            DisplayName = StringHelper.Trim(DisplayName);
            Email = StringHelper.Trim(Email);
            WorkNum = StringHelper.Trim(WorkNum);
            MobilNum = StringHelper.Trim(MobilNum);
            FullNameDat=StringHelper.Trim(FullNameDat);
            FullNameRod = StringHelper.Trim(FullNameRod);

            SqlParameter pId = new SqlParameter() { ParameterName = "id", SqlValue = Id, SqlDbType = SqlDbType.Int };
            SqlParameter pAdSid = new SqlParameter() { ParameterName = "ad_sid", SqlValue = AdSid, SqlDbType = SqlDbType.VarChar };
            SqlParameter pManager = new SqlParameter() { ParameterName = "id_manager", SqlValue = Manager.Id, SqlDbType = SqlDbType.Int };
            SqlParameter pName = new SqlParameter() { ParameterName = "name", SqlValue = Name, SqlDbType = SqlDbType.NVarChar };
            SqlParameter pSurname = new SqlParameter() { ParameterName = "surname", SqlValue = Surname, SqlDbType = SqlDbType.NVarChar };
            SqlParameter pPatronymic = new SqlParameter() { ParameterName = "patronymic", SqlValue = Patronymic, SqlDbType = SqlDbType.NVarChar };
            SqlParameter pFullName = new SqlParameter() { ParameterName = "full_name", SqlValue = FullName, SqlDbType = SqlDbType.NVarChar };
            SqlParameter pDisplayName = new SqlParameter() { ParameterName = "display_name", SqlValue = DisplayName, SqlDbType = SqlDbType.NVarChar };
            SqlParameter pPosition = new SqlParameter() { ParameterName = "id_position", SqlValue = Position.Id, SqlDbType = SqlDbType.Int };
            SqlParameter pDepartment = new SqlParameter() { ParameterName = "id_department", SqlValue = Department.Id, SqlDbType = SqlDbType.Int };
            SqlParameter pOrganization = new SqlParameter() { ParameterName = "id_organization", SqlValue = Organization.Id, SqlDbType = SqlDbType.Int };
            SqlParameter pEmail = new SqlParameter() { ParameterName = "email", SqlValue = Email, SqlDbType = SqlDbType.NVarChar };
            SqlParameter pWorkNum = new SqlParameter() { ParameterName = "work_num", SqlValue = WorkNum, SqlDbType = SqlDbType.NVarChar };
            SqlParameter pMobilNum = new SqlParameter() { ParameterName = "mobil_num", SqlValue = MobilNum, SqlDbType = SqlDbType.NVarChar };
            SqlParameter pEmpState = new SqlParameter() { ParameterName = "id_emp_state", SqlValue = EmpState.Id, SqlDbType = SqlDbType.Int };
            SqlParameter pCity = new SqlParameter() { ParameterName = "id_city", SqlValue = City.Id, SqlDbType = SqlDbType.Int };
            SqlParameter pDateCame = new SqlParameter() { ParameterName = "date_came", SqlValue = DateCame, SqlDbType = SqlDbType.Date };
            SqlParameter pBirthDate = new SqlParameter() { ParameterName = "birth_date", SqlValue = BirthDate, SqlDbType = SqlDbType.Date };
            SqlParameter pMale = new SqlParameter() { ParameterName = "male", SqlValue = Male, SqlDbType = SqlDbType.Bit };
            SqlParameter pPositionOrg = new SqlParameter() { ParameterName = "id_position_org", SqlValue = PositionOrg.Id, SqlDbType = SqlDbType.Int };
            SqlParameter pHasAdAccount = new SqlParameter() { ParameterName = "has_ad_account", SqlValue = HasAdAccount, SqlDbType = SqlDbType.Bit };
            SqlParameter pCreatorAdSid = new SqlParameter() { ParameterName = "creator_sid", SqlValue = CurUserAdSid, SqlDbType = SqlDbType.VarChar };
            SqlParameter pFullNameDat = new SqlParameter() { ParameterName = "full_name_dat", SqlValue = FullNameDat, SqlDbType = SqlDbType.NVarChar };
            SqlParameter pFullNameRod = new SqlParameter() { ParameterName = "full_name_rod", SqlValue = FullNameRod, SqlDbType = SqlDbType.NVarChar };
            SqlParameter pIdBudget = new SqlParameter() { ParameterName = "id_budget", SqlValue = IdBudget, SqlDbType = SqlDbType.Int };

            using (var conn = Db.Stuff.connection)
            {
                conn.Open();
                using (SqlTransaction tran = conn.BeginTransaction())
                {
                    try
                    {
                        var dt = Db.Stuff.ExecuteQueryStoredProcedure("save_employee", conn, tran, pId, pAdSid, pManager, pName,
                                pSurname,pPatronymic, pFullName, pDisplayName, pPosition, pDepartment, pOrganization, pEmail,
                                pWorkNum,pMobilNum, pEmpState, pCity, pDateCame, pBirthDate, pMale, pPositionOrg, pHasAdAccount, pCreatorAdSid, pFullNameDat, pFullNameRod, pIdBudget);

                        if (dt.Rows.Count > 0)
                        {
                            int id;
                            int.TryParse(dt.Rows[0]["id"].ToString(), out id);
                            Id = id;
                        }

                        if (Photo != null && Photo.Count() > 0)
                        {
                            SqlParameter pIdEmployee = new SqlParameter()
                            {
                                ParameterName = "id_employee",
                                SqlValue = Id,
                                SqlDbType = SqlDbType.Int
                            };
                            SqlParameter pPicture = new SqlParameter()
                            {
                                ParameterName = "picture",
                                SqlValue = Photo,
                                SqlDbType = SqlDbType.Image
                            };
                            Db.Stuff.ExecuteQueryStoredProcedure("save_photo", conn, tran, pIdEmployee, pPicture);
                        }

                        tran.Commit();
                    }
                    catch (Exception ex)
                    {
                        tran.Rollback();
                        throw;
                    }

                }
                conn.Close();
            }

            if (HasAdAccount && !isAdSync)
            {
                //Employee e = new Employee(Id);
                bool adCreate;
                try
                {
                    string sid = AdHelper.SaveUser(this);
                    //if (String.IsNullOrEmpty(AdSid) || AdSid != sid)
                    //{
                    //var em = new Employee(Id);
                    if (String.IsNullOrEmpty(AdSid) || AdSid != sid)
                    {
                        AdSid = sid;
                        var emp = this;
                        emp.Save(isAdSync: true);
                    }
                    //}
                    AdSid = sid;
                    adCreate = true;
                }
                catch (Exception ex)
                {
                    adCreate = false;
                    string body = String.Format("<p>Не удалось создать/обновить пользователя в Active Directory по причине:</p><p>{0}</p>", ex.Message);
                    MessageHelper.SendMailSmtp("Active Directory ERROR", body, true, ConfigurationManager.AppSettings["Emails4SysError"]);
                    //throw new Exception(String.Format("Не удалось создать пользователя в Active Directory по причине - {0}", ex.Message));
                }

                if (!isRefill && isEdit)
                {
                    string body = String.Format("<p>В систему введен новый сотрудник.</p><p>{0}</p><p>{1}</p><p>{2}</p>", FullName, Email,
                        City.Name);
                    if (!adCreate) body += "<p style='color:red; font-size: 14pt;'>Не удалось создать пользователя в AD!</p>";
                    //var recipients = AdHelper.GetRecipientsFromAdGroup(AdGroup.NewEmployeeNote);
                    var recipients = AdHelper.GetRecipientsFromAdGroup(AdGroup.NewEmployeeNote);
                    MessageHelper.SendMailSmtp("Новый сотрудник", body, true, recipients);//Оповещение сисадмину
                }
            }
        }
Example #17
0
        public HttpResponseMessage SetDeliverySend(Employee[] emps)
        {
            HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.Created);

            try
            {
                foreach (Employee emp in emps)
                {
                    Employee.SetDeliverySend(emp.Id);
                }
            }
            catch (Exception ex)
            {
                response = new HttpResponseMessage(HttpStatusCode.OK);
                response.Content = new StringContent(MessageHelper.ConfigureExceptionMessage(ex));
            }
            return response;
        }
Example #18
0
 private void FillSelf(DataRow row)
 {
     Id = Db.DbHelper.GetValueInt(row["id"]);
     AdSid = row.Table.Columns.Contains("ad_sid") ? row["ad_sid"].ToString() : String.Empty;
     Manager = new Employee() { Id = row.Table.Columns.Contains("id_manager") ? Db.DbHelper.GetValueInt(row["id_manager"]) : 0, DisplayName = row.Table.Columns.Contains("manager") ? row["manager"].ToString() : String.Empty, Email = row.Table.Columns.Contains("manager_email") ? row["manager_email"].ToString() : String.Empty };
     Surname = row.Table.Columns.Contains("surname") ? row["surname"].ToString() : String.Empty;
     Name = row.Table.Columns.Contains("name") ? row["name"].ToString() : String.Empty;
     Patronymic = row.Table.Columns.Contains("patronymic") ? row["patronymic"].ToString() : String.Empty;
     FullName = row.Table.Columns.Contains("full_name") ? row["full_name"].ToString() : String.Empty;
     DisplayName = row.Table.Columns.Contains("display_name") ? row["display_name"].ToString() : String.Empty;
     Position = new Position() { Id = row.Table.Columns.Contains("id_position") ? Db.DbHelper.GetValueInt(row["id_position"]) : 0, Name = row.Table.Columns.Contains("position") ? row["position"].ToString() : String.Empty };
     Organization = new Organization() { Id = row.Table.Columns.Contains("id_organization") ? Db.DbHelper.GetValueInt(row["id_organization"]) : 0, Name = row.Table.Columns.Contains("organization") ? row["organization"].ToString() : String.Empty };
     Email = row.Table.Columns.Contains("email") ? row["email"].ToString() : String.Empty;
     WorkNum = row.Table.Columns.Contains("work_num") ? row["work_num"].ToString() : String.Empty;
     MobilNum = row.Table.Columns.Contains("mobil_num") ? row["mobil_num"].ToString() : String.Empty;
     EmpState = new EmpState() { Id = row.Table.Columns.Contains("id_emp_state") ? Db.DbHelper.GetValueInt(row["id_emp_state"]) : 0, Name = row.Table.Columns.Contains("emp_state") ? row["emp_state"].ToString() : String.Empty };
     Department = new Department() { Id = row.Table.Columns.Contains("id_department") ? Db.DbHelper.GetValueInt(row["id_department"]) : 0, Name = row.Table.Columns.Contains("department") ? row["department"].ToString() : String.Empty };
     City = new City() { Id = row.Table.Columns.Contains("id_city") ? Db.DbHelper.GetValueInt(row["id_city"]) : 0, Name = row.Table.Columns.Contains("city") ? row["city"].ToString() : String.Empty };
     DateCame = row.Table.Columns.Contains("date_came") ? Db.DbHelper.GetValueDateTimeOrNull(row["date_came"]) : new DateTime();
     BirthDate = row.Table.Columns.Contains("birth_date") ? Db.DbHelper.GetValueDateTimeOrNull(row["birth_date"]) : new DateTime();
     Photo = row.Table.Columns.Contains("photo") ? row["photo"] == DBNull.Value ? null : Db.DbHelper.GetByteArr(row["photo"]) : null;
     IsChief = row.Table.Columns.Contains("is_chief") ? row["is_chief"].ToString().Equals("0") : false;
     Male = row.Table.Columns.Contains("male") ? row["male"].ToString().Equals("1") : true;
     PositionOrg = new Position() { Id = row.Table.Columns.Contains("id_position_org") ? Db.DbHelper.GetValueInt(row["id_position_org"]) : 0, Name = row.Table.Columns.Contains("position_org") ? row["position_org"].ToString() : String.Empty };
     HasAdAccount = row.Table.Columns.Contains("has_ad_account") ? row["has_ad_account"].ToString().Equals("1") : false;
     AdLogin = row.Table.Columns.Contains("ad_login") ? row["ad_login"].ToString() : String.Empty;
     FullNameDat = row.Table.Columns.Contains("full_name_dat") ? row["full_name_dat"].ToString() : String.Empty;
     FullNameRod = row.Table.Columns.Contains("full_name_rod") ? row["full_name_rod"].ToString() : String.Empty;
     ShortNameDat = ShortName(FullNameDat);
     ShortNameRod = ShortName(FullNameRod);
     IsHidden = row.Table.Columns.Contains("is_hidden") && Db.DbHelper.GetValueBool(row["is_hidden"].ToString());
     DateFired = Db.DbHelper.GetValueDateTimeOrNull(row, "date_fired");
     IdBudget = Db.DbHelper.GetValueIntOrNull(row, "id_budget");
 }
Example #19
0
 private void FillSelf(DataRow row)
 {
     Id = Db.DbHelper.GetValueInt(row["id"]);
     QuePosition = new QuePosition() { Id = Db.DbHelper.GetValueInt(row["id_que_position"]), Question = new Question() { Id = Db.DbHelper.GetValueInt(row["id_question"]) } };//new QuePosition(Db.DbHelper.GetValueInt(row["id_que_position"]));//
     Answerer = new Employee() { AdSid = row["answerer_sid"].ToString() };
     Descr = row["descr"].ToString();
 }
Example #20
0
 private void FillSelf(DataRow row)
 {
     Id = Db.DbHelper.GetValueInt(row["id"]);
     Name = row["name"].ToString();
     ParentDepartment = new Department() { Id = Db.DbHelper.GetValueInt(row["id_parent"]), Name = row["parent"].ToString() };
     Chief = new Employee() { Id = Db.DbHelper.GetValueInt(row["id_chief"]), DisplayName = row["chief"].ToString() };
     EmployeeCount = Db.DbHelper.GetValueIntOrDefault(row["emp_count"]);
     Hidden = row.Table.Columns.Contains("hidden") && Db.DbHelper.GetValueBool(row["hidden"]);
 }
Example #21
0
        public static Employee GetDepartmentDirector(string employeeSid)
        {
            var emp = new Employee(employeeSid);
            var dir = GetDirector();

            if (emp.Manager.AdSid == dir.AdSid || emp.AdSid==dir.AdSid) return emp;
            //Employee.GetDepartmentDirector(employeeSid);
            //GetList(idManager: GetDirector().Id)
            List<Department> orgStr = Department.GetOrgStructure(emp.Department.Id).ToList();

            //Проходимся по второй "линии" подразделений
            foreach (Department child in orgStr[0].ChildList)
            {
                var stuff = Employee.GetList(child.Id);
                if (stuff != null && stuff.Any(s => s.AdSid == employeeSid))
                {
                    return new Employee(child.Chief.Id);
                    break;
                }
                else if (CheckStuffInChilds(child, employeeSid))
                {
                    return new Employee(child.Chief.Id);
                }
            }

            return new Employee("S-1-5-21-1970802976-3466419101-4042325969-1834");
        }
Example #22
0
 private void FillSelf(DataRow row)
 {
     Id = Db.DbHelper.GetValueInt(row["id"]);
     Manager = new Employee(row["manager_sid"].ToString());
     DateLimit = Db.DbHelper.GetValueDateTime(row["date_limit"]);
     Descr = row["descr"].ToString();
     State = new QueState(Db.DbHelper.GetValueInt(row["id_que_state"]));
     DateCreate = Db.DbHelper.GetValueDateTime(row["dattim1"]);
     //State = new QueState() { Id = Db.DbHelper.GetValueInt(row["id_que_state"]), Name = row["que_state"].ToString() };
 }
Example #23
0
        private void FillSelf(DataRow row)
        {
            Id = Db.DbHelper.GetValueInt(row["id"]);
            Name = row["name"].ToString();
            EmpCount = Db.DbHelper.GetValueInt(row["emp_count"]);
            AddressUr = row["address_ur"].ToString();
            AddressFact = row["address_fact"].ToString();
            Phone = row["phone"].ToString();
            Email = row["email"].ToString();
            Inn = row["inn"].ToString();
            Kpp = row["kpp"].ToString();
            Ogrn = row["ogrn"].ToString();
            Rs = row["rs"].ToString();
            Bank = row["bank"].ToString();
            Ks = row["ks"].ToString();
            Bik = row["bik"].ToString();
            Okpo = row["okpo"].ToString();
            Okved = row["okved"].ToString();
            //ManagerName = row["manager_name"].ToString();
            //ManagerNameDat = row["manager_name_dat"].ToString();
            //ManagerPosition = row["manager_position"].ToString();
            //ManagerPositionDat = row["manager_position_dat"].ToString();
            Director = new Employee() { Id=Db.DbHelper.GetValueIntOrDefault(row["id_director"]), AdSid = row["director_sid"].ToString() };
            Site = row["site"].ToString();
            //string[] nameArr = ManagerName.Split(' ');
            //for (int i = 0;i<nameArr.Count(); i++)
            //{
            //    string name = nameArr[i];

            //    if (i > 0) name = name[0] + ".";
            //    if (i == 1) name = " " + name;
            //    ManagerShortName += name;
            //}
        }