示例#1
0
        public async Task Delete(int Id)
        {
            Com.BudgetMetal.DBEntities.User r = await repo.Get(Id);

            r.IsActive = false;
            repo.Update(r);
            repo.Commit();
        }
示例#2
0
        public async Task <VmGenericServiceResult> Update(VmUserItem vObj)
        {
            VmGenericServiceResult result = new VmGenericServiceResult();

            try
            {
                Com.BudgetMetal.DBEntities.User dbObj = await repo.Get(vObj.Id);

                Copy <VmUserItem, Com.BudgetMetal.DBEntities.User>(vObj, dbObj);

                if (vObj.RoleList != null && vObj.RoleList.Count > 0)
                {
                    foreach (var vUsrRole in vObj.RoleList)
                    {
                        var dbRoleObj = await roleRepo.Get(vUsrRole.Id);

                        if (dbRoleObj != null)
                        {
                            UserRoles ur = new UserRoles();
                            ur.Role = dbRoleObj;
                            ur.PrepareNewRecord("System");
                            dbObj.UserRoles.Add(ur);
                        }
                    }
                }
                dbObj.PrepareNewRecord("System");
                repo.Update(dbObj);

                repo.Commit();

                result.IsSuccess = true;
            }
            catch (Exception e)
            {
                result.IsSuccess = false;
                result.Error     = e;
            }

            return(result);
        }
示例#3
0
        public async Task <VmGenericServiceResult> Insert(VmUserItem vObj)
        {
            VmGenericServiceResult result = new VmGenericServiceResult();

            try
            {
                Com.BudgetMetal.DBEntities.User dbObj = new Com.BudgetMetal.DBEntities.User();

                Copy <VmUserItem, Com.BudgetMetal.DBEntities.User>(vObj, dbObj);

                #region comments
                // r.Industry_Id = 1;//hard code
                //var user = new[]
                //{
                //    new User { Id = r.Id },
                //    //new User {Id = 2}
                //};
                ////var role = new Role { Id = 1 };
                ////var role1 = new Role { Id = 2 };

                //var role = new[]
                //{
                //    new Role {Id=1},
                //    new Role {Id=2}
                //};
                //r.UserRoles.Add(new UserRoles { User = user[0], Role = role[0] });

                //r.UserRoles.Add(new UserRoles { User = user, Role = role1 });


                //foreach (var post in UserRoles)
                //{
                //    var oldPostTag = post.PostTags.FirstOrDefault(e => e.Tag.Text == "Pineapple");
                //    if (oldPostTag != null)
                //    {
                //        post.PostTags.Remove(oldPostTag);
                //        post.PostTags.Add(new PostTag { Post = post, Tag = newTag1 });
                //    }
                //    post.PostTags.Add(new PostTag { Post = post, Tag = newTag2 });
                //}
                //UserRoles _userRole = new UserRoles();
                ////_userRole.User = user[0];
                //_userRole.User_Id = r.Id;
                //_userRole.Role_Id = 1;
                ////_userRole.Role = role[0];
                //userRolesRepo.Add(_userRole);
                //userRolesRepo.Commit();
                #endregion

                if (vObj.RoleList != null && vObj.RoleList.Count > 0)
                {
                    foreach (var vUsrRole in vObj.RoleList)
                    {
                        var dbRoleObj = await roleRepo.Get(vUsrRole.Id);

                        if (dbRoleObj != null)
                        {
                            UserRoles ur = new UserRoles();
                            ur.Role = dbRoleObj;
                            ur.PrepareNewRecord("System");
                            dbObj.UserRoles.Add(ur);
                        }
                    }
                }
                dbObj.PrepareNewRecord("System");

                repo.Add(dbObj);

                repo.Commit();

                result.IsSuccess = true;
            }
            catch (Exception e)
            {
                result.IsSuccess = false;
                result.Error     = e;
            }

            return(result);
        }