public async Task AddOrganization(Organization organization, long userId)
        {
            var repository = await unitOfWork.GetRepository <IGenericRepository <Organization>, Organization>();

            var newOrganization = new Organization
            {
                Address     = organization.Address,
                Name        = organization.Name,
                Title       = organization.Title,
                IsPrivate   = organization.IsPrivate,
                PhoneNumber = organization.PhoneNumber,
                UniqueId    = organization.UniqueId,
                IsDelete    = false
            };
            await repository.AddEntity(newOrganization);

            await unitOfWork.SaveChanges();

            var organizationUserRepository = await unitOfWork.GetRepository <IGenericRepository <UserOrganization>, UserOrganization>();

            var userOrganization = new UserOrganization
            {
                UserId         = userId,
                OrganizationId = newOrganization.Id
            };

            await organizationUserRepository.AddEntity(userOrganization);

            await unitOfWork.SaveChanges();
        }
Ejemplo n.º 2
0
        public static UserOrganization ToModel(this OrganizationDTO source)
        {
            if (source == null)
            {
                return(null);
            }

            var userOrganization = new UserOrganization(source);

            if (source.Identifier != null || source.AdditionalIdentifiers?.Count > 0)
            {
                List <UserOrganizationIdentifier> allIdentifiers = new List <UserOrganizationIdentifier>();
                if (source.Identifier != null)
                {
                    allIdentifiers.Add(new UserOrganizationIdentifier(source.Identifier)
                    {
                        Main = true
                    });
                }
                if (source.AdditionalIdentifiers != null)
                {
                    allIdentifiers.AddRange(source.AdditionalIdentifiers?.Select(i => new UserOrganizationIdentifier(i)));
                }
                userOrganization.AllIdentifiers = allIdentifiers;
            }

            return(userOrganization.InitComplexProperties());
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Removes the user organization.
 /// </summary>
 /// <param name="userOrganization">The user organization.</param>
 public void RemoveUserOrganization(UserOrganization userOrganization)
 {
     if (UserOrganizations.Contains(userOrganization))
     {
         UserOrganizations.Remove(userOrganization);
     }
 }
Ejemplo n.º 4
0
        public ActionResult SaveUserOrganization(UserOrganization userOrganization)
        {
            try
            {
                using (var db = new StoreContext())
                {
                    int?cnt = db.UserOrganizations.Where(p => p.UserOrganizationId == userOrganization.UserOrganizationId).Count();

                    if (cnt == 0)
                    {
                        db.UserOrganizations.Add(userOrganization);
                    }
                    else
                    {
                        db.UserOrganizations.Attach(userOrganization);
                        db.Entry(userOrganization).State = EntityState.Modified;
                    }

                    db.SaveChanges();
                    return(Json("1", JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception ex)
            {
                return(Json(ex.Message, JsonRequestBehavior.AllowGet));
            }
        }
Ejemplo n.º 5
0
        public User Create(User user)
        {
            try
            {
                user.ID = base.Insert(user);

                UserRole userRole = new UserRole
                {
                    UserID    = user.ID,
                    RoleID    = user.Role.RoleID,
                    IsPrimary = user.Role.IsPrimary,
                    IsActive  = true
                };
                base.Insert(userRole);

                UserOrganization userOrganization = new UserOrganization()
                {
                    UserID         = user.ID,
                    OrganizationID = user.Organization.OrganizationID,
                    IsActive       = true
                };

                base.Insert(userOrganization);

                return(user);
            }

            catch (Exception ex)
            {
                _loggingManager.Log.Error(ex, ex.Source);
                throw;
            }
        }
 public void SetupMemberRel(string token, int?userid, int currentUserId)
 {
     using (DataLayerDataContext db = new DataLayerDataContext())
     {
         AddMemberToken   a = db.AddMemberTokens.FirstOrDefault(i => i.Token == token);
         UserOrganization u = new UserOrganization();
         if (a.UserId == null)
         {
             u.UserId = userid.Value;
         }
         else
         {
             u.UserId = a.UserId.Value;
         }
         u.Date       = DateTime.Now;
         u.OrgId      = a.OrgId;
         u.Permission = a.Permission;
         db.UserOrganizations.InsertOnSubmit(u);
         User j = db.Users.FirstOrDefault(r => r.Id == u.UserId);
         db.SubmitChanges();
         DeleteToken(a.Id);
         AddOrgAction(a.OrgId, currentUserId, j.FullName + " setup Relationship with you", DateTime.Now);
         AddAction(u.UserId, "Setup Relationship with organization " + u.Organization.Name, DateTime.Now);
     }
 }
Ejemplo n.º 7
0
        internal static UserOrganization ToUserOrganizationEntity(bool IsActive, UserBO User, OrganizationBO Organization)
        {
            UserOrganization UserOrganization = new UserOrganization();

            UserOrganization.Active = IsActive;

            UserOrganization.RoleId = User.Role;

            User         UserInfo         = new EFwcf.User();
            Organization OrganizationInfo = new EFwcf.Organization();

            UserInfo.EmailAddress  = User.EmailAddress;
            UserInfo.UserName      = User.EmailAddress;
            UserInfo.LastName      = User.LastName;
            UserInfo.FirstName     = User.FirstName;
            UserInfo.PhoneNumber   = User.PhoneNumber;
            UserInfo.ResetPassword = User.ResetPassword; //false;
            UserInfo.PasswordHash  = User.PasswordHash;  //"PassWord1";
            UserInfo.UGuid         = User.UGuid;
            UserOrganization.User  = UserInfo;


            OrganizationInfo.Organization1   = Organization.Organization;
            OrganizationInfo.IsEnabled       = Organization.IsEnabled;
            OrganizationInfo.OrganizationKey = Organization.OrganizationKey;

            UserOrganization.Organization = OrganizationInfo;

            return(UserOrganization);
        }
        public async Task <ActionResult <UserOrganization> > PostUserOrganization(UserOrganization userOrganization)
        {
            if (userOrganization.AuthUserId == 0)
            {
                return(BadRequest("Auth User Id cannot be empty"));
            }

            if (userOrganization.OrganizationId == 0)
            {
                return(BadRequest("Organization Id cannot be empty"));
            }

            if (string.IsNullOrWhiteSpace(userOrganization.UserAdded))
            {
                return(BadRequest("User added cannot be empty"));
            }

            userOrganization.DateAdded          = DateTime.UtcNow;
            userOrganization.UserOrganizationId = await Utils.GetNextIdAsync(_context, "user_organization");

            _context.UserOrganization.Add(userOrganization);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetUserOrganization", new { id = userOrganization.UserOrganizationId }, userOrganization));
        }
        internal long CreateMembership(UserOrganization membership)
        {
            long id = 0;

            if (membership == null)
            {
                return(id);
            }

            MembershipSchemaEntities entitiesDataContext = GetDataContext();

            membership.User = (from u in entitiesDataContext.Users
                               where u.Id == membership.IdUser
                               select u).First();
            membership.Organization = (from o in entitiesDataContext.Organizations
                                       where o.Id == membership.IdOrganization
                                       select o).First();

            entitiesDataContext.UserOrganizations.AddObject(membership);

            if (SaveChanges(entitiesDataContext))
            {
                id = membership.Id;
            }

            return(id);
        }
        public bool InsertUser(UserBO User, OrganizationBO OrgBO)
        {
            try
            {
                User.UGuid = Guid.NewGuid();
                using (var Context = DataObjectFactory.CreateContext())
                {
                    var Org = Context.Organizations.Where(x => x.OrganizationId == OrgBO.OrganizationId).Single();

                    Context.Organizations.Attach(Org);

                    Context.Users.AddObject(Mapper.ToUserEntity(User));

                    UserOrganization UserOrganizationEntity = Mapper.ToUserOrganizationEntity(User, OrgBO);
                    Context.UserOrganizations.AddObject(UserOrganizationEntity);

                    Context.SaveChanges();
                }
                return(true);
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }
Ejemplo n.º 11
0
        public void CreateUpdateDeleteUserOrganization()
        {
            UserOrganization dummyData = TestData;

            UserOrganization createdUserOrg = TestSetup.KayakoApiService.Users.CreateUserOrganization(UserOrganizationRequest.FromResponseData(dummyData));

            Assert.IsNotNull(createdUserOrg);
            dummyData.Id = createdUserOrg.Id;

            dummyData.Address          = "UPDATED: Test Address String";
            dummyData.City             = "UPDATED: City String";
            dummyData.Country          = "UPDATED: Country String";
            dummyData.Fax              = "05555666444";
            dummyData.Name             = "UPDATED: Name";
            dummyData.OrganizationType = UserOrganizationType.Shared;
            dummyData.Phone            = "02223334455";
            dummyData.PostalCode       = "BS8 1UB";

            dummyData.SlaPlanExpiry = UnixTimeUtility.ToUnixTime(DateTime.Now);
            dummyData.SlaPlanId     = 1;
            dummyData.State         = "UPDATED: State String";
            dummyData.Website       = "http://wwww.test.com";

            UserOrganization updatedUserOrg = TestSetup.KayakoApiService.Users.UpdateUserOrganization(UserOrganizationRequest.FromResponseData(dummyData));

            dummyData.Dateline    = updatedUserOrg.Dateline;
            dummyData.LastUpdated = updatedUserOrg.LastUpdated;

            Assert.IsNotNull(updatedUserOrg);
            CompareUserOrganizations(dummyData, updatedUserOrg);

            bool success = TestSetup.KayakoApiService.Users.DeleteUserOrganization(updatedUserOrg.Id);

            Assert.IsTrue(success);
        }
 public DateTime GetDateJoined(int userid, int orgid)
 {
     using (DataLayerDataContext db = new DataLayerDataContext())
     {
         UserOrganization uo = db.UserOrganizations.FirstOrDefault(i => i.UserId == userid && i.OrgId == orgid);
         return(uo.Date.Value);
     }
 }
 public Organization GetOrganizationByUser(int userid)
 {
     using (DataLayerDataContext db = new DataLayerDataContext())
     {
         UserOrganization uo = db.UserOrganizations.FirstOrDefault(i => i.UserId == userid && i.Permission != 1);
         return(db.Organizations.FirstOrDefault(i => i.Id == uo.OrgId));
     }
 }
Ejemplo n.º 14
0
        public UserOrganization PostAddUserOrganization(UserOrganization userOrgRequest)
        {
            string url = $"api/UserOrganizations";

            var result = ApiHelper.CallPostWebApi <UserOrganization, UserOrganization>(url, userOrgRequest);

            return(result);
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Удаление записи из таблицы "UserOrganizations"
        /// </summary>
        /// <param name="employeeToDelete"></param>
        private void RemoveUserOrganization(Employee employeeToDelete)
        {
            Organization organization = employeeToDelete.GetOrganization(context);
            Func <UserOrganization, bool> predicate = i => i.UserId == employeeToDelete.UserId.ToString() && i.OrganizationId == organization.Id;
            UserOrganization userOrganization       = context.UserOrganizations.FirstOrDefault(predicate);

            context.Entry(userOrganization).State = EntityState.Deleted;
            context.UserOrganizations.Remove(userOrganization);
        }
        internal UserOrganization GetMembership(int id)
        {
            MembershipSchemaEntities dc         = GetDataContext();
            UserOrganization         membership = (from uo in dc.UserOrganizations
                                                   where uo.Id == id
                                                   select uo).First();

            return(membership);
        }
        //internal bool UpdateMembership(UserOrganization membership)
        //{
        //    MembershipSchemaEntities entitiesDataContext = GetDataContext();

        //    entitiesDataContext.UserOrganizations.ApplyCurrentValues(membership);

        //    return SaveChanges(entitiesDataContext);
        //}

        internal UserOrganization GetMembership(string username, string organizationName)
        {
            MembershipSchemaEntities dc         = GetDataContext();
            UserOrganization         membership = (from uo in dc.UserOrganizations
                                                   where uo.User.UserName == username &&
                                                   uo.Organization.Name == organizationName
                                                   select uo).First();

            return(membership);
        }
        internal UserOrganization GetMembership(long userId, long organizationId)
        {
            MembershipSchemaEntities dc         = GetDataContext();
            UserOrganization         membership = (from uo in dc.UserOrganizations
                                                   where uo.IdUser == userId &&
                                                   uo.IdOrganization == organizationId
                                                   select uo).First();

            return(membership);
        }
        internal bool DeleteMembership(int id)
        {
            MembershipSchemaEntities entitiesDataContext = GetDataContext();
            UserOrganization         membership          = (from uo in entitiesDataContext.UserOrganizations
                                                            where uo.Id == id
                                                            select uo).First();

            entitiesDataContext.UserOrganizations.DeleteObject(membership);
            return(SaveChanges(entitiesDataContext));
        }
Ejemplo n.º 20
0
 public static Rest.ProcuringEntity ToRest(this UserOrganization source)
 {
     return(source == null
         ? null
         : new Rest.ProcuringEntity(source)
     {
         Identifier = source.Identifier.ToRest(),
         AdditionalIdentifiers = source.AdditionalIdentifiers?.Select(i => i.ToRest()).ToArray()
     }.DropComplexProperties());
 }
Ejemplo n.º 21
0
        internal static UserOrganization ToUserOrganizationEntity(UserBO User, OrganizationBO Organization)
        {
            UserOrganization UserOrganization = new UserOrganization();

            UserOrganization.Active         = User.IsActive;
            UserOrganization.RoleId         = User.Role;
            UserOrganization.OrganizationID = Organization.OrganizationId;


            return(UserOrganization);
        }
 /// <summary>
 /// Creates a/an UserOrganization.
 /// </summary>
 /// <param name="entity"></param>
 /// <returns>Returns the UserOrganization that was created in the database.</returns>
 public UserOrganization CreateUserOrganization(UserOrganization entity)
 {
     try
     {
         return(repo.Create <UserOrganization>(entity));
     }
     catch (Exception ex)
     {
         repo.LogError(ex);
         throw ex;
     }
 }
        public void addOrganization(Organization organization)
        {
            context.Organization.Add(organization);
            UserOrganization userOrganization = new UserOrganization();

            userOrganization.MemberId            = organization.AdminId;
            userOrganization.StatusMember        = "MEMBER";
            userOrganization.OrganizationId      = organization.Id;
            userOrganization.CurrentOrganization = false;
            context.UserOrganization.Add(userOrganization);
            context.SaveChanges();
        }
Ejemplo n.º 24
0
 public void CreateInitialUserOrdRel(int orgid, int userid)
 {
     using (DataLayerDataContext db = new DataLayerDataContext())
     {
         UserOrganization l = new UserOrganization();
         l.OrgId      = orgid;
         l.UserId     = userid;
         l.Permission = 3;
         l.Date       = DateTime.Now;
         db.UserOrganizations.InsertOnSubmit(l);
         db.SubmitChanges();
     }
 }
Ejemplo n.º 25
0
 public UserOrganizationComponent(int userId, Guid organizationId, int role, MIFNEXSOEntities mifnexsoEntities)
 {
     this.mifnexsoEntities = mifnexsoEntities;
     userOrganization      = mifnexsoEntities.UserOrganization.First(a => a.UserID == userId & a.OrganizationID == organizationId);
     if (userOrganization == null)
     {
         userOrganization = new UserOrganization();
         userOrganization.OrganizationID = organizationId;
         userOrganization.UserID         = userId;
         userOrganization.Role           = role;
         mifnexsoEntities.UserOrganization.AddObject(userOrganization);
     }
 }
        public bool UpdateUserOrganization(UserBO User, OrganizationBO OrgBO)
        {
            UserOrganization UserOrganizationEntity = Mapper.ToUserOrganizationEntity(User, OrgBO);

            using (var Context = DataObjectFactory.CreateContext())
            {
                UserOrganizationEntity.UserID = User.UserId;
                Context.AddToUserOrganizations(UserOrganizationEntity);
                Context.SaveChanges();

                return(true);
            }
        }
Ejemplo n.º 27
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            foreach (RepeaterItem item in rptOrganizations.Items)
            {
                CheckBox    chkPermission = (CheckBox)item.FindControl("chkPermission");
                HiddenField hiddenId      = (HiddenField)item.FindControl("hiddenId");
                if (_user != null)
                {
                    UserOrganization uo = null;
                    foreach (UserOrganization org in _organizations)
                    {
                        if (org.Organization.Id.ToString() == hiddenId.Value)
                        {
                            uo = org;
                            break;
                        }
                    }

                    if (uo != null && !chkPermission.Checked) //có mà bỏ check
                    {
                        Module.Delete(uo);
                    }
                    if (uo == null && chkPermission.Checked)
                    {
                        uo              = new UserOrganization();
                        uo.User         = _user;
                        uo.Organization = Module.OrganizationGetById(Convert.ToInt32(hiddenId.Value));
                        Module.SaveOrUpdate(uo);
                    }
                    //if (_organizations.Contains(hiddenName.Value) && !chkPermission.Checked) // Nếu có quyền và không có check
                    //{
                    //    SpecialPermission permission = Module.PermissionGetByRole(hiddenName.Value, _role);
                    //    if (permission!=null)
                    //    {
                    //        Module.Delete(permission);
                    //    }
                    //}
                    //else if(!_organizations.Contains(hiddenName.Value) && chkPermission.Checked)
                    //{
                    //    SpecialPermission permission = Module.PermissionGetByRole(hiddenName.Value, _role);
                    //    if (permission==null)
                    //    {
                    //        permission = new SpecialPermission
                    //                         {Name = hiddenName.Value, Role = _role, ModuleType = Section.ModuleType};
                    //        Module.SaveOrUpdate(permission);
                    //    }
                    //}
                }
            }
            PageRedirect(string.Format("SetPermission.aspx?NodeId={0}&SectionId={1}", Node.Id, Section.Id));
        }
Ejemplo n.º 28
0
        public UserOrganizationComponent(int userId, Guid organizationId, int role)
        {
            mifnexsoEntities = new MIFNEXSOEntities();

            userOrganization = mifnexsoEntities.UserOrganization.SingleOrDefault(a => a.UserID == userId & a.OrganizationID == organizationId);
            if (userOrganization == null)
            {
                userOrganization = new UserOrganization();
                userOrganization.OrganizationID = organizationId;
                userOrganization.UserID         = userId;
                userOrganization.Role           = role;
                mifnexsoEntities.UserOrganization.AddObject(userOrganization);
            }
        }
 public bool CheckIfAdminAnywhere(User u)
 {
     using (DataLayerDataContext db = new DataLayerDataContext())
     {
         UserOrganization i = db.UserOrganizations.FirstOrDefault(j => j.UserId == u.Id && j.Permission != 1);
         if (i == null)
         {
             return(false);
         }
         else
         {
             return(true);
         }
     }
 }
Ejemplo n.º 30
0
        public void GetUserOrganization()
        {
            UserOrganizationCollection userOrganizations = TestSetup.KayakoApiService.Users.GetUserOrganizations();

            Assert.IsNotNull(userOrganizations, "No user organizations were returned");
            Assert.IsNotEmpty(userOrganizations, "No user organizations were returned");

            UserOrganization userOrgToGet = userOrganizations[new Random().Next(userOrganizations.Count)];

            Trace.WriteLine("GetUserOrganization using user organization id: " + userOrgToGet.Id);

            UserOrganization userOrganization = TestSetup.KayakoApiService.Users.GetUserOrganization(userOrgToGet.Id);

            CompareUserOrganizations(userOrganization, userOrgToGet);
        }
Ejemplo n.º 31
0
        public UserOrganization CreateUserOrganization(UserOrganization uo)
        {
            db.UserOrganizations.AddObject(uo);

            SaveChanges();

            return uo;
        }
Ejemplo n.º 32
0
        public SaveResult UpdateUserOrganization(UserOrganization uo)
        {
            SaveResult result = new SaveResult { WasSuccessful = true };

            db.UserOrganizations.Attach(uo);

            db.ObjectStateManager.ChangeObjectState(uo, System.Data.EntityState.Modified);

            if (!SaveChanges())
            {
                result.WasSuccessful = false;
                result.Message = "Error updating UserOrganization";
            }

            return result;
        }
Ejemplo n.º 33
0
        public SaveResult DeleteUserOrganization(UserOrganization uo)
        {
            SaveResult result = new SaveResult { WasSuccessful = true };

            db.UserOrganizations.DeleteObject(uo);

            if (!SaveChanges())
            {
                result.WasSuccessful = false;
                result.Message = "Error deleting UserOrganization";
            }

            return result;
        }