Ejemplo n.º 1
0
 public static Event Select(int eventId)
 {
     using (var db = new Models.ModelContext())
     {
         return(db.Events.Where(e => e.Id.Equals(eventId)).FirstOrDefault());
     }
 }
Ejemplo n.º 2
0
 public static string Update(int promotionId, int state)
 {
     using (var db = new Models.ModelContext())
     {
         if (0 <= state && state < 3)
         {
             var currPromotion = db.Promotions.FirstOrDefault(p => p.Id.Equals(promotionId));
             if (currPromotion != null)
             {
                 if (currPromotion.State == (OrderState)state)
                 {
                     return("Negalima pekeisti užsakymo būsenos į tokią pačia");
                 }
                 else
                 {
                     currPromotion.State = (OrderState)state;
                     db.Update(currPromotion);
                     db.SaveChanges();
                     return("Užsakymo būsena sėkmingai atnaujinta");
                 }
             }
             else
             {
                 return("Šis užsakymas nerastas");
             }
         }
         else
         {
             return("Neteisinga užsakymo būsena");
         }
     }
 }
Ejemplo n.º 3
0
 public static User getUser(int id)
 {
     using (var db = new Models.ModelContext())
     {
         return(db.Users.Where(u => u.Id == id).FirstOrDefault());
     }
 }
Ejemplo n.º 4
0
        public static Tuple <string, bool> Insert(int eventId, int userId)
        {
            using (var db = new Models.ModelContext())
            {
                var currEvent = db.Events.Where(e => e.Id.Equals(eventId));
                var currUser  = db.Users.Where(u => u.Id.Equals(userId));

                // If any of the elements are not present in db
                if (!(currEvent.Any() && currUser.Any()))
                {
                    return(new Tuple <string, bool>("Atleiskite, įvyko klaida", false));
                }

                var schedule = db.Schedules.Where(s => (s.Event_id == eventId) && (s.User_id == userId));
                if (schedule.Any())
                {
                    return(new Tuple <string, bool>("Šis renginys jau pridėtas į Jūsų tvarkaraštį", false));
                }
                else
                {
                    var newSchedule = new Models.Schedule();
                    newSchedule.Event_id = eventId;
                    newSchedule.User_id  = userId;
                    db.Schedules.Add(newSchedule);
                    db.SaveChanges();
                    return(new Tuple <string, bool>("Renginys sėkmingai pridėtas į Jūsų tvarkaraštį.", true));
                }
            }
        }
Ejemplo n.º 5
0
 public static List <User> getUserList()
 {
     using (var db = new Models.ModelContext())
     {
         return(db.Users.ToList());
     }
 }
Ejemplo n.º 6
0
 public static User getUser(string username)
 {
     using (var db = new Models.ModelContext())
     {
         return(db.Users.Where(u => u.Username == username).FirstOrDefault());
     }
 }
Ejemplo n.º 7
0
 public static Rating Select(int eventId, int userId)
 {
     using (var db = new Models.ModelContext())
     {
         return(db.Ratings.Where(s => (s.Event_id == eventId) && (s.User_id == userId)).FirstOrDefault());
     }
 }
Ejemplo n.º 8
0
 public static string Update(int eventId, int state)
 {
     using (var db = new Models.ModelContext())
     {
         if (0 <= state && state < 3)
         {
             var currEvent = db.Events.FirstOrDefault(p => p.Id.Equals(eventId));
             if (currEvent != null)
             {
                 if (currEvent.State == (EventEnum)state)
                 {
                     return("Negalima pekeisti renginio būsenos į tokią pačia");
                 }
                 else
                 {
                     currEvent.State = (EventEnum)state;
                     db.Update(currEvent);
                     db.SaveChanges();
                     return("Užsakymo būsena sėkmingai atnaujinta");
                 }
             }
             else
             {
                 return("Šis užsakymas nerastas");
             }
         }
         else
         {
             return("Neteisinga užsakymo būsena");
         }
     }
 }
Ejemplo n.º 9
0
        public string TestDownload(int id)
        {
            var db   = new Models.ModelContext();
            var dlog = db.ImageDownloadLogSet.Find(id);


            return(Helper.WechatHelper.DownloadImgFile(dlog.MediaNumber));
        }
Ejemplo n.º 10
0
        public Models.PayParms GetPayParm()
        {
            var    prePayDic = new Dictionary <string, string>();
            string openid    = System.Configuration.ConfigurationManager.AppSettings["openId"];

            prePayDic.Add("appid", "wx551c10a5e99a84e5");
            prePayDic.Add("body", "test");
            prePayDic.Add("mch_id", "10037082");
            prePayDic.Add("nonce_str", "1add1a30ac87aa2db72f57a2375d8fec");
            prePayDic.Add("notify_url", "http://www.baidu.com/");
            prePayDic.Add("out_trade_no", "15" + DateTime.Now.Month.ToString().PadLeft(2, '0') + DateTime.Now.Day.ToString().PadLeft(2, '0') + DateTime.Now.Hour.ToString().PadLeft(2, '0') + DateTime.Now.Minute.ToString().PadLeft(2, '0') + DateTime.Now.Second.ToString().PadLeft(2, '0'));
            prePayDic.Add("spbill_create_ip", "121.40.79.86");
            prePayDic.Add("total_fee", "1");
            prePayDic.Add("trade_type", "JSAPI");
            prePayDic.Add("openid", openid);

            //        <appid>wx551c10a5e99a84e5</appid>
            //<body>test</body>
            //<mch_id>10037082</mch_id>
            //<nonce_str>1add1a30ac87aa2db72f57a2375d8fec</nonce_str>
            //<notify_url>http://www.baidu.com/</notify_url>
            //<openid>oK7_ajtkA5qGiwrU2MNqa7vs3ttE</openid>
            //<out_trade_no>out_trade_no</out_trade_no>
            //<spbill_create_ip>121.40.79.86</spbill_create_ip>
            //<total_fee>1</total_fee>
            //<trade_type>JSAPI</trade_type>
            //<sign>00492A884A794C6B3892D4406BA6DD8A</sign>
            string sign = Helper.GetMD5(prePayDic);

            prePayDic.Add("sign", sign);
            string resStr     = Helper.GerResponse(Helper.GetReqStr(prePayDic), "https://api.mch.weixin.qq.com/pay/unifiedorder");
            int    startIndex = resStr.IndexOf("<prepay_id><![CDATA[") + "<prepay_id><![CDATA[".Length;
            int    endIndex   = resStr.IndexOf("]]></prepay_id>");

            string prepayId = resStr.Substring(startIndex, endIndex - startIndex);

            Models.PayParms pp = new Models.PayParms()
            {
                timeStamp = Helper.getTimestamp()
            };
            pp.SetPackage(prepayId);

            Helper.GetMD5(ref pp);

            var db   = new Models.ModelContext();
            var user = db.UserSet.FirstOrDefault(u => u.OpenId == openid);

            if (user != null)
            {
                user.Balance += 0.01;
                db.SaveChanges();
            }
            return(pp);
        }
Ejemplo n.º 11
0
 public static string Delete(int promotionId)
 {
     using (var db = new Models.ModelContext())
     {
         var currPromotion = db.Promotions.FirstOrDefault(p => p.Id.Equals(promotionId));
         db.Promotions.Attach(currPromotion);
         db.Promotions.Remove(currPromotion);
         db.SaveChanges();
         return("Sėkmingai pašalinta reklama");
     }
 }
Ejemplo n.º 12
0
        public static string GetEventString(string toUser, string fromUser, string key)
        {
            var db   = new Models.ModelContext();
            var code = db.TwoDCodeSet.Include("Event").FirstOrDefault(c => c.EventNumber == key);

            if (code != null)
            {
                //关注事件
                if (code.Event.EeventType == Models.WechatEventType.Subscribe)
                {
                    var msgList = db.ImgMsgListSet.FirstOrDefault(ml => ml.ImgMsgListId == code.Event.ImgMsgListId);
                    if (msgList != null)
                    {
                        return(msgList.GetWechatString(toUser, fromUser));
                    }
                    else
                    {
                        return("");
                    }
                }
                else if (code.Event.EeventType == Models.WechatEventType.BeSalesman)
                {
                    var salesman = db.SalesmanSet.FirstOrDefault(s => s.EventId == code.EventId);
                    if (salesman != null)
                    {
                        var user = db.UserSet.FirstOrDefault(u => u.OpenId == toUser);
                        if (user != null)
                        {
                            salesman.UserId = user.UserId;
                            db.SaveChanges();
                            return(GetTextMsg("注册经销商成功!", toUser, fromUser));
                        }
                        else
                        {
                            return("");
                        }
                    }
                    else
                    {
                        return("");
                    }
                }
                else
                {
                    return("");
                }
            }
            else
            {
                return("");
            }
        }
Ejemplo n.º 13
0
        public static double GetRating(int eventId)
        {
            using (var db = new Models.ModelContext())
            {
                int avgRating = 0;
                var ratings   = db.Ratings.Where(s => s.Event_id == eventId).ToList();
                foreach (var rating in ratings)
                {
                    avgRating += rating.Score;
                }

                return((double)avgRating / ratings.Count());
            }
        }
Ejemplo n.º 14
0
        public static Tuple <Promotion, string, string> Select(int promotionId)
        {
            using (var db = new Models.ModelContext())
            {
                string    eventName     = "Nėra";
                string    organizerName = "Nėra";
                Promotion promotion     = db.Promotions.FirstOrDefault(p => p.Id.Equals(promotionId));
                if (promotion != null)
                {
                    organizerName = db.Users.FirstOrDefault(u => u.Id.Equals(promotion.User_id)).Username;
                    eventName     = db.Events.FirstOrDefault(e => e.Id.Equals(promotion.Event_id)).Name;
                }

                return(new Tuple <Promotion, string, string>(promotion, organizerName, eventName));
            }
        }
Ejemplo n.º 15
0
        public static Tuple <string, bool> Insert(int eventId, int userId, int ratingValue)
        {
            using (var db = new Models.ModelContext())
            {
                var currEvent = db.Events.Where(e => e.Id.Equals(eventId));
                var currUser  = db.Users.Where(u => u.Id.Equals(userId));

                // If any of the elements are not present in db
                if (!(currEvent.Any() && currUser.Any()))
                {
                    return(new Tuple <string, bool>("Atleiskite, įvyko klaida", false));
                }

                var rating = db.Ratings.Where(s => (s.Event_id == eventId) && (s.User_id == userId));
                if (!Validate(ratingValue))
                {
                    return(new Tuple <string, bool>("Jūsų įvertinimas yra netinkamas", false));
                }
                else if (rating.Any())
                {
                    foreach (var score in rating)
                    {
                        score.Score = ratingValue;
                    }
                    db.SaveChanges();
                    return(new Tuple <string, bool>("Jūsų įvertinimas pakeistas", false));
                }
                else
                {
                    var newRating = new Models.Rating();
                    newRating.Event_id = eventId;
                    newRating.User_id  = userId;
                    newRating.Score    = ratingValue;
                    db.Ratings.Add(newRating);
                    db.SaveChanges();
                    return(new Tuple <string, bool>("Renginys sėkmingai įvertintas.", true));
                }
            }
        }
Ejemplo n.º 16
0
        public IActionResult Register(string email, string username, string password, string role)
        {
            //norint kreiptis i DB reikia sukurti konteksta sitaip
            using (var db = new Models.ModelContext())
            {
                if (email != null && username != null && password != null && role != null)
                {
                    Models.User user = new Models.User();
                    user.Username = username;
                    user.Password = password;
                    if (role == "admin")
                    {
                        user.Type = Models.UserType.admin;
                    }
                    else if (role == "organizer")
                    {
                        user.Type = Models.UserType.organizer;
                    }
                    else if (role == "participant")
                    {
                        user.Type = Models.UserType.participant;
                    }
                    else
                    {
                        return(View("~/Views/Shared/Register.cshtml"));
                    }

                    db.Add(user);     //pridedam elementa i db
                    db.SaveChanges(); //pridejus reikia daryti saveChanges
                }
                else
                {
                    return(View("~/Views/Shared/Register.cshtml"));
                }
            }
            ViewData["Title"] = "Login page";
            return(View("~/Views/Shared/Login.cshtml"));
        }
Ejemplo n.º 17
0
 public static List <Event> SelectList(string option)
 {
     using (var db = new Models.ModelContext())
     {
         if (option == null || option.Equals(""))
         {
             return(db.Events.ToList());
         }
         else if (option.Equals("ended"))
         {
             var currDate = DateTime.Today;
             return(db.Events.Where(e => e.Date < currDate).ToList());
         }
         else if (option.Equals("upcoming"))
         {
             var currDate = DateTime.Today;
             return(db.Events.Where(e => e.Date >= currDate).ToList());
         }
         else
         {
             return(new List <Event>());
         }
     }
 }
Ejemplo n.º 18
0
 public static List <Tuple <Promotion, string, string> > SelectList(int option, int option2)
 {
     using (var db = new Models.ModelContext())
     {
         if (option2 == (int)Models.UserType.admin)
         {
             if (0 <= option && option < 3)
             {
                 var list = (from pr in db.Promotions
                             join usr in db.Users on pr.User_id equals usr.Id
                             join ev in db.Events on pr.Event_id equals ev.Id
                             where pr.State == (OrderState)option
                             select new Tuple <Promotion, string, string>
                             (
                                 pr,
                                 usr.Username,
                                 ev.Name
                             )
                             ).ToList();
                 return(list);
             }
             else
             {
                 var list = (from pr in db.Promotions
                             join usr in db.Users on pr.User_id equals usr.Id
                             join ev in db.Events on pr.Event_id equals ev.Id
                             select new Tuple <Promotion, string, string>
                             (
                                 pr,
                                 usr.Username,
                                 ev.Name
                             )
                             ).ToList();
                 return(list);
             }
         }
         else
         {
             if (0 <= option && option < 3)
             {
                 var list = (from pr in db.Promotions
                             join usr in db.Users on pr.User_id equals usr.Id
                             join ev in db.Events on pr.Event_id equals ev.Id
                             where pr.State == (OrderState)option
                             where usr.Id == option2
                             select new Tuple <Promotion, string, string>
                             (
                                 pr,
                                 usr.Username,
                                 ev.Name
                             )
                             ).ToList();
                 return(list);
             }
             else
             {
                 var list = (from pr in db.Promotions
                             join usr in db.Users on pr.User_id equals usr.Id
                             join ev in db.Events on pr.Event_id equals ev.Id
                             where usr.Id == option2
                             select new Tuple <Promotion, string, string>
                             (
                                 pr,
                                 usr.Username,
                                 ev.Name
                             )
                             ).ToList();
                 return(list);
             }
         }
     }
 }