コード例 #1
0
        /// <summary>
        /// find user info
        /// </summary>
        /// <param name="praiseId"></param>
        /// <param name="accountId"></param>
        /// <returns></returns>
        public VipDTO FindVip(Guid accountId)
        {
            //recover existing favoriteId and map
            var vip = _vipRepository.Get(accountId);

            if (vip != null) //adapt
            {
                return(vip.ProjectedAs <VipDTO>());
            }
            else
            {
                return(null);
            }
        }
コード例 #2
0
        public User GetUserWithLevelVip(int id)
        {
            User user = _context.Users
                        .Include(x => x.Level)
                        .Where(x => x.UserId == id)
                        .FirstOrDefault();

            if (user != null && user.VipId != null)
            {
                user.Vip = _vipRepository.Get((int)user.VipId);
            }

            return(user);
        }
コード例 #3
0
        [HttpPost]              // add vip to user
        public ActionResult <Vip> Post([FromBody] JObject data)
        {
            if (data["id"].ToString() == null)
            {
                return(Ok(new { errorcode = Errors.ErrorCode.Invalid_Json_Object }));
            }

            int userid = Int32.Parse(data["id"].ToString());
            var user   = _userRepository.Get(userid);

            if (user.VipId != null)
            {
                return(Ok(new { errocode = Errors.ErrorCode.User_Already_Has_Vip }));
            }


            var vipCreate = new Vip
            {
                StartDate     = DateTime.Now,
                EndDate       = DateTime.Now.AddDays(30),
                ExpMultiplier = new decimal(1.5),
            };

            user.Vip = vipCreate;

            _userRepository.Update(user);

            _vipRepository.Insert(vipCreate);

            if (_context.SaveChanges() > 0)
            {
                var result = _vipRepository.Get((int)_userRepository.Get(userid).VipId);
                return(Ok(result));
            }

            return(Ok(new { errorcode = Errors.ErrorCode.Insert_Vip_Error }));
        }