public void CreateUser(eBAUser userProperties)
        {
            using (var dbContext = new EBAEntities(connectionString))
            {
                OSUSERS user = new OSUSERS()
                {
                    ID = userProperties.UserId, FIRSTNAME = userProperties.FirstName, LASTNAME = userProperties.LastName, PASSWORD = userProperties.Password, EMAIL = userProperties.Email, STATUS = userProperties.Status, TYPE = 0, IMPORTSTATUS = 0, CATEGORY = 0, SEX = userProperties.Sex, DEPARTMENT = userProperties.DepartmentId, PROFESSION = userProperties.ProfessionId
                };


                OSPOSITIONS position = (from x in dbContext.OSPOSITIONS where x.ID == userProperties.PositionId select x).FirstOrDefault();

                if (position.ID != null)
                {
                    position.USERID = userProperties.UserId;
                }
                else
                {
                    OSPOSITIONS addPosition = new OSPOSITIONS {
                        ID = userProperties.PositionId, DESCRIPTION = userProperties.PositionName, IMPORTEDPOSCODE = "", IMPORTSTATUS = 0, STATUS = 1, TYPE = 0, USERID = userProperties.UserId
                    };
                    dbContext.Entry(addPosition).State = System.Data.Entity.EntityState.Added;
                }

                List <eBAUser.GroupInfo> groups = userProperties.Groups;

                if (groups.Count > 0)
                {
                    foreach (var grp in groups)
                    {
                        string tableGroup = (from c in dbContext.OSGROUPS where c.ID == grp.GroupId select c.ID).FirstOrDefault();
                        if (tableGroup != null)
                        {
                            OSGROUPCONTENT addGroup = new OSGROUPCONTENT()
                            {
                                GROUPID = grp.GroupId, USERID = userProperties.UserId
                            };
                            try
                            {
                                dbContext.Entry(addGroup).State = System.Data.Entity.EntityState.Added;
                            }
                            catch (Exception ex)
                            {
                                errorList.Add(ex.Message);
                            }
                        }
                        else
                        {
                            errorList.Add("Veritabanında " + grp.GroupId + " isminde bir grup tanımlaması yok!");
                        }
                    }
                }

                COMPANYOBJECTS company = new COMPANYOBJECTS()
                {
                    ID = userProperties.UserId, COMPANY = userProperties.CompanyId, TYPE = 1, IMPORTSTATUS = 0
                };

                OSMANAGERS manager = new OSMANAGERS()
                {
                    USERID = userProperties.UserId, MANAGERKEY = "default", MANAGERUSERID = userProperties.Manager
                };

                dbContext.Entry(user).State    = System.Data.Entity.EntityState.Added;
                dbContext.Entry(company).State = System.Data.Entity.EntityState.Added;
                dbContext.Entry(manager).State = System.Data.Entity.EntityState.Added;



                string checkUser = (from x in dbContext.OSUSERS where x.ID == userProperties.UserId select x.ID).FirstOrDefault();

                if (checkUser != null)
                {
                    errorList.Add(userProperties.UserId + " kullanıcısı zaten mevcut!");
                }
                else
                {
                    try
                    {
                        dbContext.SaveChanges();
                    }
                    catch (Exception ex)
                    {
                        errorList.Add(ex.Message);
                    }
                }
            }
        }
        public void UpdateUser(eBAUser userProperties)
        {
            using (var dbContext = new EBAEntities(connectionString))
            {
                OSUSERS user = (from x in dbContext.OSUSERS where x.ID == userProperties.UserId select x).FirstOrDefault();

                if (user != null)
                {
                    user.ID           = userProperties.UserId;
                    user.FIRSTNAME    = userProperties.FirstName;
                    user.LASTNAME     = userProperties.LastName;
                    user.PASSWORD     = userProperties.Password;
                    user.EMAIL        = userProperties.Email;
                    user.STATUS       = userProperties.Status;
                    user.TYPE         = 0;
                    user.IMPORTSTATUS = 0;
                    user.CATEGORY     = 0;
                    user.SEX          = userProperties.Sex;
                    user.DEPARTMENT   = userProperties.DepartmentId;
                    user.PROFESSION   = userProperties.ProfessionId;
                }
                else
                {
                    errorList.Add(userProperties.UserId + " kullanıcısı bulunamadı!");
                }


                OSMANAGERS manager = (from x in dbContext.OSMANAGERS where x.USERID == userProperties.UserId select x).FirstOrDefault();
                if (manager != null)
                {
                    manager.MANAGERKEY    = "default";
                    manager.MANAGERUSERID = userProperties.Manager;
                }
                else
                {
                    OSMANAGERS addManager = new OSMANAGERS {
                        USERID = userProperties.UserId, MANAGERKEY = "default", MANAGERUSERID = userProperties.Manager
                    };
                    dbContext.Entry(addManager).State = System.Data.Entity.EntityState.Added;
                }

                List <OSGROUPCONTENT> currGroups = (from x in dbContext.OSGROUPCONTENT where x.USERID == userProperties.UserId select x).ToList();
                foreach (var grp in currGroups)
                {
                    dbContext.Entry(grp).State = System.Data.Entity.EntityState.Deleted;
                    dbContext.SaveChanges();
                }

                foreach (var newGroup in userProperties.Groups)
                {
                    var groupCheck = (from x in dbContext.OSGROUPS where x.ID == newGroup.GroupId select x).FirstOrDefault();

                    if (groupCheck != null)
                    {
                        OSGROUPCONTENT cnt = new OSGROUPCONTENT()
                        {
                            GROUPID = newGroup.GroupId, USERID = userProperties.UserId
                        };
                        dbContext.Entry(cnt).State = System.Data.Entity.EntityState.Added;
                        dbContext.SaveChanges();
                    }
                    else
                    {
                        errorList.Add("Veritabanında " + newGroup.GroupId + " ID'si ile bir grup bulunmadığından kullanıcıya atama gerçekleştirilemedi.");
                    }
                }

                try
                {
                    dbContext.SaveChanges();
                }
                catch (Exception ex)
                {
                    errorList.Add(ex.Message);
                }
            }
        }