コード例 #1
0
        /// <summary>
        /// to get page full detail
        /// </summary>
        /// <param name="encryptedId"></param>
        /// <returns></returns>
        public UserStoreModel GetDetail(string encryptedId)
        {
            UserStoreModel model = new UserStoreModel();

            try
            {
                int UserId = Convert.ToInt32(encryptedId);
                #region get detail
                model = UnitofWork.RepoUserStore.Where(x => x.UserID == UserId && x.User.IsActive == true).Select(x => new UserStoreModel
                {
                    UserID      = x.UserID ?? 0,
                    UserStoreID = x.UserStoreID,
                    StoreName   = x.Store.Storename,
                    StoreID     = x.StoreID ?? 0,
                    OwnerName   = x.User.Ownername ?? "",
                }).FirstOrDefault();
                #endregion

                if (model != null)
                {
                    model.EncryptedID = model.UserID.ToString().ToEnctypt();
                }
                else
                {
                    model = new UserStoreModel();
                }
            }
            catch (Exception ex)
            {
                EventLogHandler.WriteLog(ex);
            }
            return(model);
        }
コード例 #2
0
        public ActionResult SaveUserStore(UserStoreModel model)
        {
            TransactionMessage TransMessage = new TransactionMessage();

            TransMessage.Status = MessageStatus.Error;
            try
            {
                if (ModelState.IsValid)
                {
                    model = _store.UserStoreSave(model);
                    if (model.TransMessage.Status == MessageStatus.Success)
                    {
                        SuccessNotification(model.TransMessage.Message);
                    }
                }
                else
                {
                    TransMessage.Message = utilityHelper.ReadGlobalMessage("ManageStore", "ErrorMessage");
                }
            }
            catch (Exception ex)
            {
                // write exception log
                EventLogHandler.WriteLog(ex);
            }
            return(Json(model.TransMessage, JsonRequestBehavior.DenyGet));
        }
コード例 #3
0
        public ActionResult Add(string id)
        {
            UserStoreModel model = new UserStoreModel();

            model.UserID      = Convert.ToInt32(id);
            model.OwnerName   = _user.GetDetail(id.ToEnctypt()).OwnerName;
            ViewBag.StoreList = _common.GetStoreList();
            return(View(model));
        }
コード例 #4
0
        /// <summary>
        /// to save or update Page
        /// </summary>
        /// <param name="model">UsersModel</param>
        /// <returns>UsersModel</returns>
        public UserStoreModel Save(UserStoreModel model)
        {
            model.TransMessage        = new TransactionMessage();
            model.TransMessage.Status = MessageStatus.Error;
            try
            {
                #region check duplicate
                if (UnitofWork.RepoUserStore.Where(x => x.StoreID == model.StoreID && x.UserID == model.UserID).Count() > 0)
                {
                    model.TransMessage.Message = utilityHelper.ReadGlobalMessage("ManageStoreOption", "Duplicate");
                    return(model);
                }
                #endregion

                UserStore dbuserStore = UnitofWork.RepoUserStore.Where(x => x.UserStoreID == model.UserStoreID).FirstOrDefault();

                bool isSave = false;

                if (dbuserStore == null)
                {
                    #region Save
                    dbuserStore = new UserStore();
                    UnitofWork.RepoUserStore.Add(dbuserStore);
                    model.TransMessage.Message = utilityHelper.ReadGlobalMessage("ManageStoreOption", "Save");
                    isSave = true;
                    #endregion
                }
                else
                {
                    #region Update
                    model.TransMessage.Message = utilityHelper.ReadGlobalMessage("ManageStoreOption", "Update");
                    #endregion
                }
                #region Set Value
                dbuserStore.UserID  = model.UserID;
                dbuserStore.StoreID = model.StoreID;
                #endregion

                UnitofWork.Commit();
                model.TransMessage.Status = MessageStatus.Success;
            }
            catch (Exception ex)
            {
                EventLogHandler.WriteLog(ex);
            }
            return(model);
        }
コード例 #5
0
ファイル: ChatStore.cs プロジェクト: halliba/Flexx
        private static IEnumerable <UserStoreModel> LoadUsers(XContainer userRoot)
        {
            if (userRoot == null)
            {
                yield break;
            }

            foreach (var element in userRoot.Elements("User"))
            {
                var name = element.Attribute("Name")?.Value;
                if (string.IsNullOrWhiteSpace(name))
                {
                    continue;
                }

                var publicKey = element.Attribute("PublicKey")?.Value;
                if (string.IsNullOrWhiteSpace(publicKey))
                {
                    continue;
                }

                var lastActivityString = element.Attribute("LastActivity")?.Value;
                if (string.IsNullOrWhiteSpace(lastActivityString) ||
                    !DateTime.TryParse(lastActivityString, out var lastActivity))
                {
                    continue;
                }

                var user = new UserStoreModel
                {
                    Name         = name,
                    PublicKey    = publicKey,
                    LastActivity = lastActivity
                };
                yield return(user);
            }
        }
コード例 #6
0
        public string Authenticate(string email, string password, out UserStoreModel outUserStore)
        {
            var user = _dbContext.Users.FirstOrDefault(x => x.Email == email && x.Password == password);

            outUserStore = null;
            if (user == null)
            {
                return(MessageForUser.LOGIN_INVALID);
            }

            var tokenHandler    = new JwtSecurityTokenHandler();
            var key             = Encoding.ASCII.GetBytes(_appSettings.Secret);
            var tokenDescriptor = new SecurityTokenDescriptor
            {
                Subject = new ClaimsIdentity(new Claim[]
                {
                    new Claim(ClaimTypes.Name, user.UserId.ToString())
                }),
                Expires            = DateTime.UtcNow.AddDays(7),
                SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature)
            };
            var token = tokenHandler.CreateToken(tokenDescriptor);

            user.Token = tokenHandler.WriteToken(token);

            outUserStore = _mapper.Map(user, outUserStore);

            var userStore = _dbContext.UserStores.FirstOrDefault(x => x.UserId == user.UserId);

            if (userStore != null)
            {
                outUserStore.StoreId = userStore.StoreId;
            }

            return("");
        }