Exemple #1
0
 // GET: api/Topic
 public DTO.ReturnJasonConstruct <List <DTO.Topic> > Get()
 {
     try
     {
         string[] separators = { "@||@" };
         DTO.ReturnJasonConstruct <List <DTO.Topic> > dto = new DTO.ReturnJasonConstruct <List <DTO.Topic> >();
         dto.status    = (int)DTO.executeStatus.success;
         dto.DTOObject = new List <DTO.Topic>();
         UserInformationEntities db = new UserInformationEntities();
         var objectList             = db.TopicStack.ToList();
         foreach (var item in objectList)
         {
             DTO.Topic obj = new DTO.Topic();
             obj.topic   = item.Topic;
             obj.choices = new List <DTO.Choice>();
             string[] choices = item.Choices.Split(separators, StringSplitOptions.RemoveEmptyEntries);
             string[] goal    = item.Goals.Split(separators, StringSplitOptions.RemoveEmptyEntries);
             for (int n = 0; n < choices.Length; n++)
             {
                 obj.choices.Add(new DTO.Choice
                 {
                     choice = choices[n],
                     goal   = int.Parse(goal[n])
                 });
             }
             dto.DTOObject.Add(obj);
         }
         return(dto);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemple #2
0
        public ReturnJasonConstruct <DTO.User> SetUserShare([FromBody] DTO.User user)
        {
            DateTime dt        = DateTime.Now;
            DateTime startTime = new DateTime(dt.Year, dt.Month, dt.Day, 0, 0, 0);

            dt = dt.AddDays(1);
            DateTime endTime           = new DateTime(dt.Year, dt.Month, dt.Day, 0, 0, 0);
            UserInformationEntities db = new UserInformationEntities();
            var lotteryObjects         = db.lottery1.Where(p => p.UserID == user.id && p.LotteryDate >= startTime && p.LotteryDate <= endTime).ToList();

            ReturnJasonConstruct <DTO.User> dto = new ReturnJasonConstruct <DTO.User>();

            //检查当天有没有抽过奖。如果抽过奖,直接跳过。
            if (lotteryObjects.Count == 0)
            {
                dto.status      = (int)executeStatus.warning;
                dto.information = "今天还没有抽奖";
            }
            else if (lotteryObjects.Count == 1 && !lotteryObjects[0].Share)
            {
                lotteryObjects[0].Share = true;
                db.SaveChanges();
                dto.status      = (int)executeStatus.success;
                dto.information = "恭喜您获得额外抽奖一次的机会";
            }
            else
            {
                dto.status      = (int)executeStatus.warning;
                dto.information = "今天分享获得额外抽奖的次数已经满额,请明天再继续分享.";
            }

            return(dto);
        }
Exemple #3
0
        private DTO.User GetExp(Guid userId, ref UserInformationEntities db)
        {
            if (db.User.Where(p => p.ID == userId).Count() == 0)
            {
                throw new Exception("没有指定ID的用户信息.");
            }

            try
            {
                var result = db.User.Single(p => p.ID == userId);
                result.Exp += expIncrease;
                if (result.Exp > maxExp)
                {
                    if (result.Level == levelMax)
                    {
                        result.Exp = maxExp;
                    }
                    else
                    {
                        result.Exp = 0;
                        result.Level++;
                    }
                }

                return(result.ToDTO());
            }
            catch
            {
                throw new Exception("设置用户经验时出错.");
            }
        }
 public bool IsEmailExist(string emailID)
 {
     using (UserInformationEntities db = new UserInformationEntities())
     {
         var v = db.tblUsers.Where(a => a.EmailID == emailID).FirstOrDefault();
         return(v != null);
     }
 }
Exemple #5
0
        public ReturnJasonConstruct <DTO.User> Put([FromBody] DTO.User user)
        {
            try
            {
                ReturnJasonConstruct <DTO.User> dto = new ReturnJasonConstruct <DTO.User>();
                if (CheckObjectAvalible(user, ref dto) == false)
                {
                    return(dto);
                }

                UserInformationEntities db = new UserInformationEntities();
                if (user.id.ToString() == "" || db.User.Where(p => p.ID == user.id).Count() == 0)
                {//创建用户
                    var result = db.User.Where(p => p.Tel == user.tel);
                    if (result.Count() > 0)
                    {
                        dto.status      = (int)executeStatus.warning;
                        dto.information = "该电话号码已经被注册.";
                        return(dto);
                    }

                    Models.User ac = new Models.User();
                    ac.ID         = Guid.NewGuid();
                    ac.UserName   = user.name;
                    ac.Tel        = user.tel;
                    ac.Exp        = 0;
                    ac.Level      = 0;
                    ac.password   = user.password;
                    ac.CreateDate = DateTime.Now;
                    db.User.Add(ac);
                    dto.DTOObject = ac.ToDTO();
                }
                else//更新用户
                {
                    var result = db.User.Single(p => p.ID == user.id);
                    result.UserName = user.name;
                    result.Tel      = user.tel;
                    result.password = user.password;
                    result.Exp      = user.exp;
                    result.Level    = ConvertDTO.GetLevelInt(user.level);
                    dto.DTOObject   = result.ToDTO();
                }
                db.SaveChanges();
                dto.status = (int)executeStatus.success;
                return(dto);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public ActionResult Registration([Bind(Exclude = "IsEmailVerified,ActivationCode")] tblUser user)
        {
            bool   Status  = false;
            string message = "";

            //
            //Model Validation
            if (ModelState.IsValid)
            {
                #region//Email is already exist
                var isExist = IsEmailExist(user.EmailID);
                if (isExist)
                {
                    ModelState.AddModelError("EmailExist", "Email already exist");
                    return(View(user));
                }
                #endregion

                #region //Generate Activation Code
                user.ActivationCode = Guid.NewGuid();
                #endregion

                #region                                                   //Password Hashing
                user.Password        = Crypto.Hash(user.Password);
                user.ConfirmPassword = Crypto.Hash(user.ConfirmPassword); //
                #endregion

                user.IsEmailVerified = false;
                #region //Save to Database
                using (UserInformationEntities db = new UserInformationEntities())
                {
                    db.tblUsers.Add(user);
                    db.SaveChanges();
                }
                #endregion
                #region //Send Email to user
                SendVerificationLink(user.EmailID, user.ActivationCode.ToString());
                message = @"Registration succesfully done. Account verification link has been sent to 
                            your email id -> " + user.EmailID;
                Status  = true;
                #endregion
            }
            else
            {
                message = "Invalid Request";
            }
            ViewBag.Message = message;
            ViewBag.Status  = Status;
            return(View(user));
        }
        public ActionResult Login(UserLogin login, string ReturnUrl = "")
        {
            string message = "";

            ViewBag.Message = message;

            using (UserInformationEntities db = new UserInformationEntities())
            {
                var v = db.tblUsers.Where(a => a.EmailID == login.EmailID).FirstOrDefault();
                if (v != null)
                {
                    if (string.Compare(Crypto.Hash(login.Password), v.Password) == 0)
                    {
                        int    timeout   = login.RememberMe ? 525600 : 20; // 525600min = 1 year
                        var    ticket    = new FormsAuthenticationTicket(login.EmailID, login.RememberMe, timeout);;
                        string encrypted = FormsAuthentication.Encrypt(ticket);
                        var    cookie    = new HttpCookie(FormsAuthentication.FormsCookieName, encrypted);
                        cookie.Expires  = DateTime.Now.AddMinutes(timeout);
                        cookie.HttpOnly = true;
                        Response.Cookies.Add(cookie);


                        if (Url.IsLocalUrl(ReturnUrl))
                        {
                            return(Redirect(ReturnUrl));
                        }
                        else
                        {
                            return(RedirectToAction("Index", "Home"));
                        }
                    }
                    else
                    {
                        message = "Invalid credentials provided";
                    }
                }
                else
                {
                    message = "Invalid credentials provided";
                }
            }

            return(View());
        }
Exemple #8
0
        // GET: api/Gift/5
        public DTO.ReturnJasonConstruct <List <DTO.Gift> > Get(Guid id)
        {
            UserInformationEntities db = new UserInformationEntities();
            var q = from c in db.lottery1
                    from d in db.LotteryGift
                    where c.LotteryGiftID == d.ID && c.UserID == id && d.GiftName != "谢谢惠顾" && c.Receive == false
                    select new
            {
                GiftName        = d.GiftName,
                GiftDescribtion = d.GiftDescribtion,
                remark          = c.UberID
            };

            DTO.ReturnJasonConstruct <List <DTO.Gift> > giftList = new DTO.ReturnJasonConstruct <List <DTO.Gift> >();
            giftList.status    = (int)DTO.executeStatus.success;
            giftList.DTOObject = new List <DTO.Gift>();
            foreach (var item in q)
            {
                string remark = "";
                if (item.GiftName.IndexOf("优步") != -1)
                {
                    var uberObj = db.UBer.SingleOrDefault(p => p.ID == item.remark);
                    if (uberObj != null)
                    {
                        remark = "优惠码:" + uberObj.ExchangeNumber.ToString();
                    }
                }
                //DTO.ReturnJasonConstruct<List<DTO.Gift>> dto = new DTO.ReturnJasonConstruct<List<DTO.Gift>>();
                DTO.Gift dtoObject = new DTO.Gift();
                dtoObject.giftName        = item.GiftName;
                dtoObject.giftDescribtion = item.GiftDescribtion;
                dtoObject.remark          = remark;

                giftList.DTOObject.Add(dtoObject);
            }

            return(giftList);
        }
Exemple #9
0
        public ReturnJasonConstruct <DTO.User> Get(Guid id)
        {
            try
            {
                ReturnJasonConstruct <DTO.User> dto = new ReturnJasonConstruct <DTO.User>();
                UserInformationEntities         db  = new UserInformationEntities();
                if (db.User.Where(p => p.ID == id).Count() == 0)
                {
                    dto.status      = (int)executeStatus.warning;
                    dto.information = "没有该用户或用户名密码不对,请检查键入的用户信息.";
                    return(dto);
                }

                var result = db.User.Single(p => p.ID == id);
                dto.status    = (int)executeStatus.success;
                dto.DTOObject = result.ToDTO();
                return(dto);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public ActionResult VerifyAccount(string id)
        {
            bool status = false;

            using (UserInformationEntities db = new UserInformationEntities())
            {
                db.Configuration.ValidateOnSaveEnabled = false; //This line here I have added to avoid confirm password
                                                                //does not match issue on save changes

                var v = db.tblUsers.Where(a => a.ActivationCode == new Guid(id)).FirstOrDefault();
                if (v != null)
                {
                    v.IsEmailVerified = true;
                    db.SaveChanges();
                    status = true;
                }
                else
                {
                    ViewBag.Message = "Invalid Request";
                }
            }
            ViewBag.Status = status;
            return(View());
        }
Exemple #11
0
        private DTO.RollLettory SaveLottery(Guid userId, ref UserInformationEntities db, ref LotteryGift gift, ref LotteryGift defaultGift, ref RollLottery rl)
        {
            var      DTO     = new DTO.RollLettory();
            lottery1 lottery = new lottery1();

            lottery.UserID      = userId;
            lottery.LotteryDate = DateTime.Now;
            lottery.Share       = false;
            lottery.Receive     = false;
            if (gift.Num == 0)
            {
                lottery.LotteryGiftID = defaultGift.ID;
                DTO.rotate            = rl.GetGiftByGiftName(defaultGift.GiftName) * position + 22;
                DTO.results           = defaultGift.GiftName;
                //记录DTO数据
                DTO.giftName = defaultGift.GiftName;
                DTO.giftDes  = defaultGift.GiftDescribtion;
            }
            else
            {
                //如果包含Uber信息
                //--优步劵没有了,就给默认奖品,即谢谢惠顾
                //--如果优步劵还有,就指定优步劵并且关联优步优惠劵
                //如果不是优步,就直接减少奖品数量,并且关联奖品
                if (gift.GiftName.Contains("优步") || gift.GiftName.Contains("Uber"))
                {
                    if (db.UBer.Where(p => !p.Use).Count() <= 0)
                    {
                        lottery.LotteryGiftID = defaultGift.ID;
                        DTO.rotate            = rl.GetGiftByGiftName(defaultGift.GiftName) * position + 22;
                        DTO.results           = defaultGift.GiftName;
                        //记录DTO数据
                        DTO.giftName = defaultGift.GiftName;
                        DTO.giftDes  = defaultGift.GiftDescribtion;
                    }
                    else
                    {
                        lottery.LotteryGiftID = gift.ID;
                        DTO.rotate            = rl.GetGiftByGiftName(gift.GiftName) * position + 22;
                        DTO.results           = gift.GiftName;
                        var UberObj = db.UBer.First(p => !p.Use);
                        lottery.UberID = UberObj.ID;
                        UberObj.Use    = true;
                        //记录DTO数据
                        DTO.giftName = gift.GiftName;
                        DTO.giftDes  = gift.GiftDescribtion;
                        DTO.remark   = UberObj.ExchangeNumber;
                    }
                }
                else
                {
                    lottery.LotteryGiftID = gift.ID;
                    gift.Num--;
                    //记录DTO数据
                    DTO.rotate   = rl.GetGiftByGiftName(gift.GiftName) * position + 22;
                    DTO.results  = gift.GiftName;
                    DTO.giftName = gift.GiftName;
                    DTO.giftDes  = gift.GiftDescribtion;
                }
            }
            db.lottery1.Add(lottery);
            DTO.user = GetExp(userId, ref db);
            db.SaveChanges();
            return(DTO);
        }
Exemple #12
0
        public ReturnJasonConstruct <DTO.RollLettory> Get(Guid userId)
        {
            try
            {
                DateTime dt = DateTime.Now;
                ReturnJasonConstruct <DTO.RollLettory> dto = new ReturnJasonConstruct <DTO.RollLettory>();
                DateTime startTime = new DateTime(dt.Year, dt.Month, dt.Day, 0, 0, 0);
                dt = dt.AddDays(1);
                DateTime endTime           = new DateTime(dt.Year, dt.Month, dt.Day, 0, 0, 0);
                UserInformationEntities db = new UserInformationEntities();

                //获取默认奖项
                LotteryGift defaultGift = null;
                if (db.LotteryGift.Where(p => p.GiftName == defaultGiftName).Count() == 0)
                {
                    dto.status      = (int)executeStatus.warning;
                    dto.information = "无法获取默认奖项";
                    return(dto);
                }
                defaultGift = db.LotteryGift.Single(p => p.GiftName == defaultGiftName);

                //检查抽奖概率基数
                LotteryGift selectGift = null;
                var         items      = db.LotteryGift.AsQueryable().Where(p => !p.Expired).OrderBy(p => p.ID).ToList();
                if (items.Count() == 0)
                {
                    dto.status      = (int)executeStatus.warning;
                    dto.information = "没有抽奖项目.";
                    return(dto);
                }
                if (items.Count() != lotteryCount)
                {
                    dto.status      = (int)executeStatus.warning;
                    dto.information = "抽奖项目必须为8个.";
                    return(dto);
                }

                //初始化奖品信息
                RollLottery rl = new RollLottery();
                foreach (var item in items)
                {
                    rl.SetGift(item.GiftName, item.Probability);
                }
                //首先检查是否有指定的礼物,如果有,直接返回。
                var gift = db.LotteryGift.Where(p => p.Owner == userId && p.Num > 0).ToList();
                if (gift.Count() > 0)
                {
                    selectGift    = gift[0];
                    dto.status    = (int)executeStatus.success;
                    dto.DTOObject = SaveLottery(userId, ref db, ref selectGift, ref defaultGift, ref rl);
                    return(dto);
                }

                //var lotteryObjects = db.lottery1.Where(p => p.UserID == userId && p.LotteryDate >= startTime && p.LotteryDate <= endTime).ToList();
                ////检查当天有没有抽过奖。如果抽过奖,直接跳过。
                //if (!(lotteryObjects.Count == 0 || (lotteryObjects.Count == 1 && lotteryObjects[0].Share)))
                //{
                //    dto.status = (int)executeStatus.warning;
                //    dto.information = "今天已经抽过奖了.";
                //    return dto;
                //}

                rl.GetProbability();
                long index      = rl.GetGiftIndex(ref WebApiApplication.randomSeed);
                var  giftObject = items[(int)index];

                selectGift    = giftObject;
                dto.status    = (int)executeStatus.success;
                dto.DTOObject = SaveLottery(userId, ref db, ref selectGift, ref defaultGift, ref rl);
                return(dto);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }