예제 #1
0
        /// <summary>
        /// 添加社团
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task <IActionResult> AddAnAssociation(Guid id)
        {
            var entity = await _anAssociationRepository.GetAll().Include(x => x.User).Where(x => x.ID == id).FirstOrDefaultAsync();

            if (entity == null)
            {
                return(Json(new { isOK = false, message = "没有这条数据" }));
            }
            var user = User.Claims.FirstOrDefault();

            if (user == null)
            {
                return(Json(new { isOK = false, message = "请登录!!!" }));
            }
            var entityUser = _anAssociationAndUserExtension.GetAll().Include(x => x.AnAssociation).Include(x => x.AnAssociation.User)
                             .Include(x => x.User).Where(x => x.User.Id == user.Value && x.AnAssociationId == id).FirstOrDefault();

            if (entityUser != null)
            {
                return(Json(new { isOK = false, message = "你已经是社团成员,不可重复加入" }));
            }
            ;
            var userInfo = await _userManager.FindByIdAsync(user.Value);

            var anAssociationAndUser = new AnAssociationAndUser {
                User = userInfo, AnAssociationId = id
            };

            _anAssociationAndUserExtension.AddAndSave(anAssociationAndUser);
            await AddMessageNotification(entity.User, id, entity.Name, entity.Name + "社团新成员:" + userInfo.Name, BusinessEmergencyEnum.一般);

            return(Json(new { isOK = true, message = "成功加入" }));
        }
예제 #2
0
        /// <summary>
        /// 用于存储或更新活动
        /// </summary>
        /// <param name="anVM"></param>
        /// <returns></returns>
        public async Task <IActionResult> Sava([Bind("ID,UserId,Name,SchoolAddress,CreateDataTime,MaxNumber,Description")] AnAssociationVM anVM)
        {
            var an = await _anAssociationRepository.GetSingleAsyn(anVM.ID);

            if (an == null)
            {
                an = new AnAssociation();
                var userclaims = User.Claims.FirstOrDefault();
                var userData   = await _userManager.FindByIdAsync(userclaims.Value.ToString());

                an.User = userData;
                var anFounder = new AnAssociationAndUser()
                {
                    User                  = userData,
                    AnAssociationId       = anVM.ID,
                    AnJurisdictionManager = AnJurisdiction.Founder
                };
                an.IsDisable = true;
                _anAssociationAndUserExtension.Add(anFounder);
            }
            anVM.MapToAn(an);
            var savaStatus = await _anAssociationRepository.AddOrEditAndSaveAsyn(an);

            if (an == null)
            {
                _anAssociationAndUserExtension.Save();
            }
            if (savaStatus)
            {
                return(RedirectToAction("Index"));
            }
            else
            {
                ModelState.AddModelError("", "数据保存出现异常,无法创建活动。");
                return(View("~/Views/GroupOrganization/AnAssociation/CreateOrEdit.cshtml", anVM));
            }
        }