예제 #1
0
        // GET: wx/OfficalAccounts
        public ActionResult Index()
        {
            var firstOne = _repository.Query().FirstOrDefault();

            if (firstOne == null)
            {
                firstOne       = new WxOfficalAccount();
                firstOne.Token = CreateKey(8);
            }

            return(View(firstOne));
        }
예제 #2
0
        private WxOfficalAccount GetOfficalAccount(string id = null)
        {
            WxOfficalAccount account = null;

            if (!string.IsNullOrWhiteSpace(id))
            {
                account = _offcicalAccountRepo.Query().FirstOrDefault(x => x.Id == id);
            }
            else
            {
                account = _offcicalAccountRepo.Query().FirstOrDefault();
            }
            return(account);
        }
예제 #3
0
        public ActionResult Edit(WxOfficalAccount model)
        {
            if (ModelState.IsValid)
            {
                var isOk = RunWithCatch((ms) =>
                {
                    var isNew  = false;
                    var entity = _repository.Query().FirstOrDefault();
                    if (entity == null)
                    {
                        isNew  = true;
                        entity = _mapper.Map <WxOfficalAccount>(model);
                    }
                    else
                    {
                        entity.AppId                 = model.AppId;
                        entity.AppSecret             = model.AppSecret;
                        entity.Token                 = model.Token;
                        entity.EndPoint              = model.EndPoint;
                        entity.UsingWxLoginFunction  = model.UsingWxLoginFunction;
                        entity.MediaSourceServerPath = model.MediaSourceServerPath;
                        entity.MicroSiteHeaderImages = model.MicroSiteHeaderImages;
                        entity.MicroSiteName         = model.MicroSiteName;
                    }

                    if (isNew)
                    {
                        return(_repository.Insert(entity));
                    }
                    else
                    {
                        return(_repository.Update(entity, p => new object[] { entity.Id }));
                    }
                });

                if (isOk)
                {
                    return(RedirectToAction("Index"));
                }
            }

            return(View("Index", model));
        }