Exemplo n.º 1
0
        public async Task <IActionResult> SubmitFeedback(UserFeedbackVM input)
        {
            var strList = new List <string> {
                input.Description
            };

            if (StrIsNull(strList) || input.Type == UserFeedbackType.未选择)
            {
                return(Json(new { result = false, contentNull = true, message = "必填项为空,请检查类型和描述是否已经选择和填写!" }));
            }
            var user         = GetUser();
            var userFeedback = new UserFeedback
            {
                Link              = EncodeFilterHelper.EncodeHtmlForLink(input.Link),
                Description       = EncodeFilterHelper.EncodeHtml(input.Description),
                ContactWay        = EncodeFilterHelper.EncodeHtml(input.ContactWay),
                Type              = input.Type,
                FeedbackIPAddress = GetClientIpAddress(),
                FeedUser          = user == null ? null : user
            };
            var r = await _userFeedback.AddOrEditAndSaveAsyn(userFeedback);

            if (r)
            {
                return(Json(new { result = true }));
            }
            return(Json(new { result = false, message = "提交失败!" }));
        }
Exemplo n.º 2
0
        public async Task <JsonResult> SaveChangeProfile([Bind("Name,MobileNumber,QQNumber,EMail,Description")] ApplicationUserVM boVM)
        {
            if (string.IsNullOrEmpty(boVM.EMail))
            {
                return(Json(new { result = false, message = "电子邮件必须填写!" }));
            }
            //var entity = await _userManager.FindByIdAsync(boVM.Id.ToString());
            var thisUser = await _userManager.FindByNameAsync(User.Identity.Name);

            if (thisUser != null)
            {
                thisUser.ChineseFullName = EncodeFilterHelper.EncodeHtmlToNull(boVM.Name);
                thisUser.MobileNumber    = boVM.MobileNumber;
                thisUser.Email           = EncodeFilterHelper.EncodeHtml(boVM.EMail);
                thisUser.QQNumber        = boVM.QQNumber;
                thisUser.Description     = EncodeFilterHelper.EncodeHtmlToNull(boVM.Description);

                var update = await _userManager.UpdateAsync(thisUser);

                if (update.Succeeded)
                {
                    var thisIntegrity = UserInfoIntegrity() + "%";
                    var thisUsername  = GetCurrUserName();
                    return(Json(new { result = true, integrity = thisIntegrity, username = thisUsername }));
                }
                return(Json(new { result = false, message = "修改失败" }));
            }
            return(Json(new { result = false, message = "修改失败" }));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> CreateSiteNotice(SiteNoticeVM input)
        {
            if (string.IsNullOrEmpty(input.Name) || string.IsNullOrEmpty(input.Description))
            {
                return(Json(new { result = false, message = "必填项为空,请检查标题和内容是否已经选择和填写!" }));
            }
            var siteNotice = new SiteNotice
            {
                Publisher   = GetUser(),
                Name        = EncodeFilterHelper.EncodeHtml(input.Name),
                Description = EncodeFilterHelper.EncodeHtml(input.Description)
            };
            var r = await _siteNotice.AddOrEditAndSaveAsyn(siteNotice);

            if (r)
            {
                await UploadNoticeIMG(siteNotice);

                return(Json(new { result = true }));
            }
            return(Json(new { result = false, message = "发布失败,请重试!" }));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Register([Bind("Id,IsNew,UserName,EMail,Password,ConfirmPassword")] ApplicationUserVM boVM)
        {
            if (!GetSiteConfiguration().CanRegister)
            {
                return(Json(new { result = false, message = "管理员已经禁用注册!请关注公告!" }));
            }
            if (GetCurrUserName() != null)
            {
                return(RedirectToAction("UserCenter", "Account"));
            }
            if (boVM.UserName == null || boVM.EMail == null || boVM.Password == null || boVM.ConfirmPassword == null)
            {
                return(Json(new { result = false, message = "表单中的所有必填项存在空值,请检查!" }));
            }
            if (_HasTheSameUser(boVM.UserName))
            {
                return(Json(new { result = false, message = "当前用户名已经被使用了!" }));
            }
            var user = new ApplicationUser(EncodeFilterHelper.EncodeHtml(boVM.UserName))
            {
                Email = EncodeFilterHelper.EncodeHtml(boVM.EMail)
            };

            //普通用户
            const string averageUser = "******";
            //判断用户组是否存在
            var roleExists = await _roleManager.RoleExistsAsync(averageUser);

            if (!roleExists)
            {
                ApplicationRole userRole = new ApplicationRole()
                {
                    Name = averageUser, DisplayName = "普通注册用户", Description = "适用于普通注册用户", ApplicationRoleType = ApplicationRoleTypeEnum.适用于普通注册用户, SortCode = "99avf56g"
                };
                await _roleManager.CreateAsync(userRole);
            }
            var a1 = await _userManager.CreateAsync(user);

            var a2 = await _userManager.AddPasswordAsync(user, boVM.Password);

            //注册完成添加默认头像
            var avatar = new BusinessImage
            {
                Name              = string.Empty,
                DisplayName       = string.Empty,
                OriginalFileName  = string.Empty,
                Type              = ImageType.Avatars,
                RelevanceObjectId = Guid.Parse(user.Id),
                UploaderId        = Guid.Parse(user.Id),
                Description       = "这是用户【" + user.UserName + "】的个人头像",
                FileSize          = 0,
                UploadPath        = "../../images/Avatars/defaultAvatar.gif",
                PhysicalPath      = string.Empty
            };
            await _businessImage.AddOrEditAndSaveAsyn(avatar);

            //查询用户是否已经添加了权限 若不在添加进用户组
            if (!await _userManager.IsInRoleAsync(user, averageUser))
            {
                var roleOK = await _userManager.AddToRoleAsync(user, averageUser);
            }
            if (a1.Succeeded && a2.Succeeded)
            {
                var message      = "恭喜您注册成功,注册时间[" + user.CreateTime + "],请牢记您的用户名[" + user.UserName + "]。";
                var notification = new Notification
                {
                    Receiver           = user,
                    Name               = "用户注册",
                    Description        = message,
                    Link               = "javascript:",
                    IsAbnormal         = false,
                    IsRead             = false,
                    NotificationSource = NotificationSourceEnum.App
                };
                AppNotification.SendNotification(notification);
                return(Json(new { result = true, message = "注册成功,请牢记您的账号密码!", userName = user.UserName, password = boVM.Password }));
            }
            else
            {
                return(Json(new { result = false, message = "注册失败,在短时间内只能注册一次!" }));
            }
        }
        public async Task <JsonResult> AddOrEditCommodity([Bind("Id,IsNew,Name,Description,Price,Unit,Stock,State,Way,Range,IsBargain,CategoryId")] YZ_CommodityVM boVM)
        {
            var commodity = new YZ_Commodity();
            var category  = _commodityCategory.GetAll().FirstOrDefault(x => x.Id == boVM.CategoryId);

            if (boVM.IsNew)
            {
                var lookCount = new YZ_CommodityLookCount {
                    LookCount = 0
                };
                _commodityLookCount.AddAndSave(lookCount);
                commodity = new YZ_Commodity
                {
                    Name           = EncodeFilterHelper.EncodeHtml(boVM.Name),
                    Description    = EncodeFilterHelper.EncodeHtml(boVM.Description),
                    Unit           = EncodeFilterHelper.EncodeHtml(boVM.Unit),
                    State          = YZ_CommodityState.IsExamine,
                    Category       = category == null ? null : category,
                    Price          = boVM.Price,
                    Stock          = boVM.Stock,
                    LookCount      = lookCount,
                    AscriptionUser = GetUser(),
                    EditTime       = DateTime.Now,
                    IsBargain      = boVM.IsBargain,
                    Way            = boVM.Way,
                    Range          = boVM.Range
                };
            }
            else
            {
                commodity = await _commodity.GetSingleAsyn(boVM.Id);

                if (commodity != null)
                {
                    commodity.Name        = EncodeFilterHelper.EncodeHtml(boVM.Name);
                    commodity.Description = EncodeFilterHelper.EncodeHtml(boVM.Description);
                    commodity.Price       = boVM.Price;
                    commodity.Unit        = EncodeFilterHelper.EncodeHtml(boVM.Unit);
                    commodity.Stock       = boVM.Stock;
                    commodity.AddTime     = commodity.AddTime;
                    commodity.State       = boVM.State; //调试时不修改商品状态
                    commodity.Category    = category == null ? null : category;
                    commodity.EditTime    = DateTime.Now;
                    commodity.IsBargain   = boVM.IsBargain;
                    commodity.Way         = boVM.Way;
                    commodity.Range       = boVM.Range;
                }
            }
            //图片上传独立处理
            AddCommodityImg(commodity);
            var result = await _commodity.AddOrEditAndSaveAsyn(commodity);

            if (result)
            {
                if (boVM.IsNew)
                {
                    return(Json(new { result = true, message = "添加成功!" }));
                }
                else
                {
                    return(Json(new { result = true, message = "修改成功!" }));
                }
            }
            else
            {
                return(Json(new { result = false, message = "操作失败!" }));
            }
        }