コード例 #1
0
        public ActionResult Create(Personnel personnel, HttpPostedFileBase file)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    //image upload
                    if (file == null || !isImageValid(file))
                    {
                        ModelState.AddModelError(string.Empty, string.Empty);
                    }
                    else
                    {
                        isActivePersonel(personnel);
                        db.Insert(personnel);

                        //Save Image File to Local
                        string imagePath = "~/Uploads/Images/" + "Image_" + personnel.ID + ".png";
                        saveImage(file, imagePath);

                        //Save Image Path to DB and Update Personnel
                        personnel.PhotoPath = imagePath;
                        db.Update(personnel);

                        return(RedirectToAction("Index"));
                    }
                }
                catch (Exception)
                {
                    throw;
                }
            }
            return(View(personnel));
        }
コード例 #2
0
ファイル: Db.cs プロジェクト: sur-ser/AkinatorEngine
        public void QuestionUpdateOnDbSide(Model.Question q)
        {
            var a = _db.SingleOrDefault <Question>($"SELECT * FROM {_tblQ} WHERE question_id={q.Id}");

            a.hidden_from_ui         = q.HiddenFromUi;
            a.shown_only_for_doctors = q.ShownOnlyForDoctors;
            a.text = q.Text;

            _db.Update(a);
        }
コード例 #3
0
        public void BasicCRUD()
        {
            var db = new PetaPoco.Database("Chinook");
            var newID = db.Insert(new Artist
            {
                Name = "Woot"
            });

            var acdcnew = db.Update(new Artist { ArtistId = 1, Name = "AC/DC Blah" });
            var acdc = db.Update(new Artist { ArtistId = 1, Name = "AC/DC" });
        }
コード例 #4
0
        /// <summary>
        ///  更新单条数据
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="tbName"></param>
        /// <param name="primaryKeyValue"></param>
        /// <param name="t"></param>
        /// <returns></returns>
        public int UpdateModel <T>(string tbName, string primaryKeyValue, T t)
        {
            int _intRlt = 0;

            _intRlt = db.Update(tbName, primaryKeyValue, t);
            return(_intRlt);
        }
コード例 #5
0
ファイル: App.Monitor.cs プロジェクト: thompsonson/LPS
        public static void StopAll()
        {
            var db = new PetaPoco.Database("LocalSQLite");

            // stop all running threads\monitors
            foreach (MonitorClass mc in _monitorRunPool)
            {
                // stop the Timer
                if (!mc.DisableTimer())
                {
                    log.WarnFormat("Unable to disable the timer for Monitor ID: {0}", mc.MonitorID);
                }
                // TODO: Does the thread need joining back??

                // change the monitor state
                try
                {
                    Model.Monitor monitor = db.Single <Model.Monitor>("Select * from Monitor WHERE MonitorID = @monitorID", new { monitorID = mc.MonitorID });
                    monitor.State = Model.MonitorState.Idle.ToString();
                    db.Update(monitor);
                }
                catch (Exception ex)
                {
                    log.WarnFormat("Unable to set the monitor state to Idle for monitor ID: {0}", mc.MonitorID);
                    log.ErrorFormat(ex.ToString());
                }
            }
        }
コード例 #6
0
 public int UpdateCommonInfoData(CommonInfo model)
 {
     using (PetaPoco.Database context = new PetaPoco.Database("DefaultConnection"))
     {
         return((int)context.Update(model));
     }
 }
コード例 #7
0
ファイル: Program.cs プロジェクト: ciker/MicroORM
        private static void Crud()
        {
            var petaPoco = new PetaPoco.Database("Chinook");

            var customer = new Customer {
                FirstName = "Ian", LastName = "Russell", Email = "*****@*****.**"
            };

            petaPoco.Insert(customer);

            var id = customer.CustomerId;

            customer = petaPoco.Single <Customer>(id);

            ObjectDumper.Write(customer);

            customer.Country = "United Kingdom";

            petaPoco.Update(customer);

            customer = petaPoco.Single <Customer>(id);

            ObjectDumper.Write(customer);

            petaPoco.Delete <Customer>(id);

            customer = petaPoco.SingleOrDefault <Customer>(id);

            ObjectDumper.Write(customer);
        }
コード例 #8
0
ファイル: Program.cs プロジェクト: ciker/MicroORM
        private static void Crud()
        {
            var petaPoco = new PetaPoco.Database("Chinook");

            var customer = new Customer { FirstName = "Ian", LastName = "Russell", Email = "*****@*****.**" };

            petaPoco.Insert(customer);

            var id = customer.CustomerId;

            customer = petaPoco.Single<Customer>(id);

            ObjectDumper.Write(customer);

            customer.Country = "United Kingdom";

            petaPoco.Update(customer);

            customer = petaPoco.Single<Customer>(id);

            ObjectDumper.Write(customer);

            petaPoco.Delete<Customer>(id);

            customer = petaPoco.SingleOrDefault<Customer>(id);

            ObjectDumper.Write(customer);
        }
コード例 #9
0
        public ActionResult Edit(sanpham sp)
        {
            try
            {
                if (HttpContext.Request.Files.Count > 0)
                {
                    var hpf = HttpContext.Request.Files[0];
                    if (hpf.ContentLength > 0)
                    {
                        string filename = Guid.NewGuid().ToString();

                        string fullPathWithFileName = "/images/" + filename + ".jpg";
                        hpf.SaveAs(Server.MapPath(fullPathWithFileName));
                        sp.hinhanh = fullPathWithFileName;
                    }
                }
                // TODO: Add update logic here
                //QuanLyBus.CapNhat(id,sp);
                var dataContext = new PetaPoco.Database("DienThoaiShopConnection");
                dataContext.Update("sanpham", "MaSanPham", sp);
                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
コード例 #10
0
        public static bool UpdateSettings(Dictionary <string, string> dic)
        {
            using (PetaPoco.Database db = new PetaPoco.Database("sqlconnection"))
            {
                try
                {
                    db.BeginTransaction();

                    foreach (var d in dic)
                    {
                        var r = db.Query <Models.Settings>(" where title=@0", d.Key).SingleOrDefault();
                        r.Value = d.Value;
                        db.Update(r);
                    }

                    db.CompleteTransaction();
                    return(true);
                }
                catch
                {
                    db.AbortTransaction();
                    return(false);
                }
            }
        }
コード例 #11
0
 public int updateWoodProp(WoodProp prop)
 {
     using (PetaPoco.Database context = new PetaPoco.Database("DefaultConnection"))
     {
         return((int)context.Update(prop));
     }
 }
コード例 #12
0
        public int GeraNovo_NumeroNFiscal()
        {
            var db       = new PetaPoco.Database("stringConexao");
            int iNFiscal = 0;

            try
            {
                db.BeginTransaction();


                //Buscando o numero da ultima nota fiscal emitida e gerando um novo numero
                iNFiscal = (this.getNumNFiscal() + 1);

                //Atualizando o numero da nota fiscal no banco de dados
                db.Update("Update Controle Set NFiscal_NFCe=" + iNFiscal + " Where ChvControle = 1");


                Controle.getInstance.ultima_NFCe = Convert.ToInt32(iNFiscal);


                db.CompleteTransaction();
            }
            catch (Exception)
            {
                db.AbortTransaction();
                return(0);
            }

            return(iNFiscal);
        }
コード例 #13
0
 public int updateBamboo(bamboo bamboo)
 {
     using (PetaPoco.Database context = new PetaPoco.Database("DefaultConnection"))
     {
         return((int)context.Update(bamboo));
     }
 }
コード例 #14
0
        public ActionResult Edit(Contacts contact)
        {
            var dataContext = new PetaPoco.Database("sqladdress");

            dataContext.Update("contacts", "id", contact);

            return(RedirectToAction("Index"));
        }
コード例 #15
0
ファイル: POST.ashx.cs プロジェクト: ekah/pinsite
        private void fbLogin(HttpContext context)
        {
            string token = context.Request.Params["token"];

            Facebook.FacebookClient client = new Facebook.FacebookClient(token);
            //client.Post()
            client.UseFacebookBeta = client.IsSecureConnection = true;
            Facebook.JsonObject o = (Facebook.JsonObject)client.Get("/me");
            var db = new PetaPoco.Database(Common.HairStyleConnectionString, "System.Data.SqlClient");

            using (var scope = db.GetTransaction())
            {
                try
                {
                    string         first_name = (string)o["first_name"];
                    string         name       = (string)o["name"];
                    decimal        id         = Convert.ToDecimal(o["id"]);
                    POCOS.Facebook fb         = new POCOS.Facebook();
                    fb.name       = name;
                    fb.first_name = first_name;
                    fb.gender     = (string)o["gender"];
                    fb.id         = id;
                    fb.last_name  = (string)o["last_name"];
                    fb.link       = (string)o["link"];
                    fb.locale     = (string)o["locale"];
                    fb.timezone   = Convert.ToDouble(o["timezone"]);
                    string   updatedtime = (string)o["updated_time"];
                    DateTime dt;
                    if (DateTime.TryParse(updatedtime, out dt))
                    {
                        fb.updated_time = dt;
                    }
                    if (db.Exists <POCOS.Facebook>(id))
                    {
                        db.Update(fb);
                    }
                    else
                    {
                        db.Insert(fb);
                    }
                    POCOS.AppUser au = POCOS.AppUser.FirstOrDefault("Select top 1 * from AppUsers where facebookid=@0", id);
                    if (au == null)
                    {
                        au            = new POCOS.AppUser();
                        au.FirstName  = first_name;
                        au.facebookid = id;
                        db.Insert(au);
                    }
                    scope.Complete();
                    CookieUtil.WriteCookie(Common.AuthCookie, EncDec.Encrypt(JsonConvert.SerializeObject(new { ID = au.ID }), Common.DefaultPassword), false);
                    CookieUtil.WriteCookie(Common.InfoCookie, JsonConvert.SerializeObject(new { email = au.Email, name = au.Name, avatar = string.IsNullOrWhiteSpace(au.Avatar) ? null : Common.UploadedImageRelPath + au.Avatar }), false);
                }
                finally
                {
                    scope.Dispose();
                }
            }
        }
コード例 #16
0
 public static bool UpdateUserInfo(Models.User user)
 {
     using (PetaPoco.Database db = new PetaPoco.Database("sqlconnection"))
     {
         var u = db.Query <Models.User>("WHERE uid=@0 ", user.Uid).SingleOrDefault();
         u = user;
         return(db.Update(u) >= 0);
     }
 }
コード例 #17
0
 public static bool DeleteTopic(int fid)
 {
     using (PetaPoco.Database db = new PetaPoco.Database("sqlconnection"))
     {
         var entity = db.Query <Models.Forums>("where fid=@0", fid).SingleOrDefault();
         entity.IsHidden = 1;
         return(db.Update(entity) > 0);
     }
 }
コード例 #18
0
 public static bool SetTopicTop(int fid, Int16 istop)
 {
     using (PetaPoco.Database db = new PetaPoco.Database("sqlconnection"))
     {
         var entity = db.Query <Models.Forums>("where fid=@0", fid).SingleOrDefault();
         entity.IsTop = istop;
         return(db.Update(entity) > 0);
     }
 }
コード例 #19
0
 public static bool UpdateUserGroup(string groupName, object gid)
 {
     using (PetaPoco.Database db = new PetaPoco.Database("sqlconnection"))
     {
         var model = db.Query <UserGroup>("where gid=@0", Convert.ToInt32(gid)).SingleOrDefault();
         model.GroupName = groupName;
         return(db.Update(model) > 0);
     }
 }
コード例 #20
0
 public void UpdateYeZhu(YeZhu yz)
 {
     if (yz.log == null)
     {
         yz.log = "";
     }
     if (Config.Conn.State == System.Data.ConnectionState.Closed)
     {
         Config.Conn.Open();
     }
     DB.Update(yz);
 }
コード例 #21
0
 public static bool UpdateLink(Models.Links model)
 {
     using (PetaPoco.Database db = new PetaPoco.Database("sqlconnection"))
     {
         var entity = db.Query <Models.Links>("where id=@0", model.Id).SingleOrDefault();
         entity.IsHidden = model.IsHidden;
         entity.Logo     = model.Logo;
         entity.Name     = model.Name;
         entity.Url      = model.Url;
         return(db.Update(entity) > 0);
     }
 }
コード例 #22
0
 public static Models.Forums GetForum(int id)
 {
     using (PetaPoco.Database db = new PetaPoco.Database("sqlconnection"))
     {
         var f = db.SingleOrDefault <Models.Forums>("WHERE fid=@0", id);
         if (f != null)
         {
             f.Views++;
             db.Update(f, new string[] { "views" });
         }
         return(f);
     }
 }
コード例 #23
0
        public void Handle(AccountCreditedEvent domainEvent)
        {
            // Update the Read database
            Console.WriteLine("Updating account record {0}", domainEvent.Amount.ToString("C"));

            using (var db = new PetaPoco.Database("DemoConnectionString"))
            {
                var account = db.Single <BankAccountReadModel>(domainEvent.Id);
                account.CurrentBalance += domainEvent.Amount;

                db.Update(account);
            }
        }
コード例 #24
0
 public object POST([FromBody] Novedad item) {
     try {
         var db = new PetaPoco.Database("jlapc");
         if (item.NovedadID == 0) {
             db.Insert(item);
         } else {
             db.Update(item);
         }
         return (new JsonResult() { Data = new { ok = true, error = "" }, JsonRequestBehavior = JsonRequestBehavior.AllowGet }).Data;
     } catch (Exception e) {
         return (new JsonResult() { Data = new { ok = false, error = e.Message }, JsonRequestBehavior = JsonRequestBehavior.AllowGet }).Data;
     }
 }
コード例 #25
0
 public static bool UpdateCategory(Category model)
 {
     using (PetaPoco.Database db = new PetaPoco.Database("sqlconnection"))
     {
         var entity = GetCategoryInfo(model.CId);
         entity.CName    = model.CName;
         entity.Content  = model.Content;
         entity.Keywords = model.Keywords;
         entity.Master   = model.Master;
         entity.Permit   = model.Permit;
         entity.PId      = model.PId;
         return(db.Update(entity) > 0);
     }
 }
コード例 #26
0
 public void CancelTicket(int id)
 {
     using (var db = new PetaPoco.Database(ConnectionString, providerName))
     {
         List <int> SeatIds = db.Fetch <int>("SELECT SeatId from Tickets where Id = @0", id);
         for (int i = 0; i < SeatIds.Count; i++)
         {
             var Seat = db.SingleOrDefault <Seat>(SeatIds[i]);
             Seat.Occupied = false;
             db.Update(Seat);
         }
         db.Delete <Ticket>(id);
     }
 }
コード例 #27
0
ファイル: ForumDataProvider.cs プロジェクト: ouyang90/XBBS
        public static bool AddComment(Models.Comment comment)
        {
            var f = GetForum(comment.FId);
            if (f == null) return false;
            using (PetaPoco.Database db = new PetaPoco.Database("sqlconnection"))
            {
                f.LastReply = DateTime.Now;
                f.Comments++;
                f.Ruid = comment.UId;
                db.Update(f, new string[] { "lastreply", "comments","ruid" });

                return db.Insert(comment) != null;
            }
        }
コード例 #28
0
        private void NotifyVote()
        {
            var db  = new PetaPoco.Database("AGSoftware");
            var db2 = new PetaPoco.Database("AGSoftware");
            var db3 = new PetaPoco.Database("AGSoftware");
            var db4 = new PetaPoco.Database("AGSoftware");

            foreach (var a in db.Query <Entities.Vote>("Select * From Vote v Where v.UserNotified = 0"))
            {
                var b = db2.SingleOrDefault <Entities.StorytimePost>("Select * from Storytimepost Where StorytimePostId = @0", a.StorytimePostId);
                var c = db2.SingleOrDefault <Entities.Storytime>("Select * from Storytime Where StorytimeId = @0", b.StorytimeId);
                var d = db2.SingleOrDefault <Entities.StorytimeGroup>("Select * from StorytimeGroup Where StorytimeId = @0", c.StorytimeId);

                if (c.StorytimeTypeId == 1)
                {
                    var e = db2.SingleOrDefault <Entities.UserGroup>("Select * from UserGroup Where UserGroupId = @0", d.UserGroupId);

                    foreach (var f in db3.Query <Entities.UserGroupUser>("Select * From UserGroupUser Where UserGroupId = @0", e.UserGroupId))
                    {
                        if (f != null)
                        {
                            var g = db4.SingleOrDefault <Entities.AspNetUsers>("Select * from AspNetUsers Where Id = @0", f.UserId);

                            if (g != null && g.DeviceToken != null)
                            {
                                string notificationtext = newvote + " " + g.UserName + " has voted for " + b.PostText;
                                CreatePushNotification(newvote, g.DeviceToken);
                            }
                        }
                    }
                }
                else if (c.StorytimeTypeId == 2)
                {
                    foreach (var h in db3.Query <Entities.StorytimeUserList>("Select * from StorytimeUserList Where StorytimeId = @0", c.StorytimeId))
                    {
                        var i = db4.SingleOrDefault <Entities.AspNetUsers>("Select * from AspNetUsers Where Id = @0", h.UserId);

                        if (i != null && i.DeviceToken != null)
                        {
                            string notificationtext = newvote + " " + i.UserName + " has voted for " + b.PostText;
                            CreatePushNotification(newvote, i.DeviceToken);
                        }
                    }
                }

                a.UserNotified = true;
                db2.Update(a);
            }
        }
コード例 #29
0
        public Show PostSave(Show show)
        {
            var db = new PetaPoco.Database("umbShow");

            if (show.idShow > 0)
            {
                db.Update(show);
            }
            else
            {
                db.Insert(show);
            }

            return(show);
        }
コード例 #30
0
        private void NotifyStoryWinner()
        {
            var db  = new PetaPoco.Database("AGSoftware");
            var db2 = new PetaPoco.Database("AGSoftware");
            var db3 = new PetaPoco.Database("AGSoftware");
            var db4 = new PetaPoco.Database("AGSoftware");

            foreach (var a in db.Query <Entities.Storytime>("select * from storytime s where (select count(*) from storytimeseries ss where ss.storytimeid = s.storytimeid) = 10 and s.UsersNotified = 0"))
            {
                var b = db2.SingleOrDefault <Entities.StoryWinner>("Select top 1 sum(sp.votes) as votes, u.username, s.storytimetitle from storytimeseries ss inner join storytimepost sp on ss.StorytimeSeriesId = sp.SeriesId inner join AspNetUsers u on u.id = sp.UserId inner join storytime s on s.storytimeid = ss.storytimeid where ss.storytimeid = @0 group by u.username, s.storytimetitle order by votes desc", a.StorytimeId);

                if (a.StorytimeTypeId == 1)
                {
                    var c = db2.SingleOrDefault <Entities.StorytimeGroup>("Select * from StorytimeGroup Where StorytimeId = @0", a.StorytimeId);
                    var d = db2.SingleOrDefault <Entities.UserGroup>("Select * from UserGroup Where UserGroupId = @0", c.UserGroupId);

                    foreach (var e in db3.Query <Entities.UserGroupUser>("Select * From UserGroupUser Where UserGroupId = @0", d.UserGroupId))
                    {
                        if (e != null)
                        {
                            var f = db4.SingleOrDefault <Entities.AspNetUsers>("Select * from AspNetUsers Where Id = @0", e.UserId);

                            if (f != null && f.DeviceToken != null)
                            {
                                CreatePushNotification(storywinner + f.UserName + " has won the story " + a.StorytimeTitle + " with " + b.Votes + " !", f.DeviceToken);
                            }
                        }
                    }
                }
                else if (a.StorytimeTypeId == 2)
                {
                    foreach (var g in db3.Query <Entities.StorytimeUserList>("Select * from StorytimeUserList Where StorytimeId = @0", a.StorytimeId))
                    {
                        var h = db4.SingleOrDefault <Entities.AspNetUsers>("Select * from AspNetUsers Where Id = @0", g.UserId);

                        if (h != null && h.DeviceToken != null)
                        {
                            CreatePushNotification(storywinner + h.UserName + " has won the story " + a.StorytimeTitle + " with " + b.Votes + " !", h.DeviceToken);
                        }
                    }
                }

                a.UsersNotified = true;
                db4.Update(a);
            }
        }
コード例 #31
0
        public static bool AddComment(Models.Comment comment)
        {
            var f = GetForum(comment.FId);

            if (f == null)
            {
                return(false);
            }
            using (PetaPoco.Database db = new PetaPoco.Database("sqlconnection"))
            {
                f.LastReply = DateTime.Now;
                f.Comments++;
                f.Ruid = comment.UId;
                db.Update(f, new string[] { "lastreply", "comments", "ruid" });

                return(db.Insert(comment) != null);
            }
        }
コード例 #32
0
        public IHttpActionResult Post([FromUri] string id)
        {
            var db   = new PetaPoco.Database("AGSoftware");
            var vote = new Entities.Vote();

            vote.StorytimePostId = int.Parse(id);
            vote.DateCreated     = System.DateTime.Now;
            vote.UserId          = Storytime.Providers.UserHelper.GetUserId(this.User.Identity.Name);
            vote.UserNotified    = false;
            db.Insert(vote);

            var storytimepost = db.SingleOrDefault <Entities.StorytimePost>("Select * from StorytimePost Where StorytimePostId = @0", id);

            storytimepost.Votes = storytimepost.Votes + 1;
            db.Update(storytimepost);

            return(Ok());
        }
コード例 #33
0
 public bool Modificar(clsUsuario Obj)
 {
     try
     {
         if (GetByLogOn(Obj.User_LogOn) == null)
         {
             throw new UserException();
         }
         Obj.User_Pasw = EncriptarPass(Obj.User_Pasw);
         var res = db.Update(Obj);
         return(true);
     }
     catch (Exception ex)
     {
         Utiles.WriteErrorLog("En usuarioManager actualizar " + ex.Message);
         Obj = null;
         return(false);
     }
 }
コード例 #34
0
        public void BookSeats(int MovieId, int TheaterId, string userId, List <int> Seatids)
        {
            using (var db = new PetaPoco.Database(ConnectionString, providerName))
            {
                for (int i = 0; i < Seatids.Count; i++)
                {
                    var seat = db.SingleOrDefault <Seat>(Seatids[i]);
                    seat.Occupied = true;
                    db.Update(seat);

                    db.Insert(new Ticket
                    {
                        MovieId   = MovieId,
                        TheatreId = TheaterId,
                        UserId    = userId,
                        SeatId    = Seatids[i]
                    });
                }
            }
        }
コード例 #35
0
        private void NotifyNewStory()
        {
            var db = new PetaPoco.Database("AGSoftware");
            var db2 = new PetaPoco.Database("AGSoftware");
            var db3 = new PetaPoco.Database("AGSoftware");

            foreach (var a in db.Query<Entities.StorytimeUserList>("Select * From StorytimeUserList Where UserNotified = 0"))
            {
                var b = db2.SingleOrDefault<Entities.AspNetUsers>("Select * from AspNetUsers Where Id = @0", a.UserId);
                var storytime = db2.SingleOrDefault<Entities.Storytime>("Select * from Storytime Where StorytimeId = @0", a.StorytimeId);

                if (storytime.UserId != b.Id && b.DeviceToken != null)
                {
                    CreatePushNotification(newstory + storytime.StorytimeTitle, b.DeviceToken);
                }

                a.UserNotified = true;
                db2.Update(a);
            }

            foreach (var c in db.Query<Entities.StorytimeGroup>("Select * from StorytimeGroup Where UsersNotified = 0"))
            {
                var d = db2.SingleOrDefault<Entities.UserGroup>("Select * from UserGroup Where UserGroupId = @0", c.UserGroupId);
                var storytime = db2.SingleOrDefault<Entities.Storytime>("Select * from Storytime Where StorytimeId = @0", c.StorytimeId);

                foreach (var e in db3.Query<Entities.UserGroupUser>("Select * from UserGroupUser Where UserGroupId = @0", d.UserGroupId))
                {
                    var f = db2.SingleOrDefault<Entities.AspNetUsers>("Select * from AspNetUsers Where Id = @0", e.UserId);

                    if (f != null && f.Id != storytime.UserId && f.DeviceToken != null)
                    {
                        CreatePushNotification(newstory + storytime.StorytimeTitle, f.DeviceToken);
                    }
                }

                c.UsersNotified = true;
                db3.Update(c);
            }
        }
コード例 #36
0
        private void NotifyVote()
        {
            var db = new PetaPoco.Database("AGSoftware");
            var db2 = new PetaPoco.Database("AGSoftware");
            var db3 = new PetaPoco.Database("AGSoftware");
            var db4 = new PetaPoco.Database("AGSoftware");

            foreach (var a in db.Query<Entities.Vote>("Select * From Vote v Where v.UserNotified = 0"))
            {
                var b = db2.SingleOrDefault<Entities.StorytimePost>("Select * from Storytimepost Where StorytimePostId = @0", a.StorytimePostId);
                var c = db2.SingleOrDefault<Entities.Storytime>("Select * from Storytime Where StorytimeId = @0", b.StorytimeId);
                var d = db2.SingleOrDefault<Entities.StorytimeGroup>("Select * from StorytimeGroup Where StorytimeId = @0", c.StorytimeId);

                if (c.StorytimeTypeId == 1)
                {
                    var e = db2.SingleOrDefault<Entities.UserGroup>("Select * from UserGroup Where UserGroupId = @0", d.UserGroupId);

                    foreach(var f in db3.Query<Entities.UserGroupUser>("Select * From UserGroupUser Where UserGroupId = @0", e.UserGroupId))
                    {
                        if (f != null)
                        {
                            var g = db4.SingleOrDefault<Entities.AspNetUsers>("Select * from AspNetUsers Where Id = @0", f.UserId);

                            if (g != null && g.DeviceToken != null)
                            {
                                string notificationtext = newvote + " " + g.UserName + " has voted for " + b.PostText;
                                CreatePushNotification(newvote, g.DeviceToken);
                            }
                        }
                    }
                }
                else if(c.StorytimeTypeId == 2)
                {
                    foreach (var h in db3.Query<Entities.StorytimeUserList>("Select * from StorytimeUserList Where StorytimeId = @0", c.StorytimeId))
                    {
                        var i = db4.SingleOrDefault<Entities.AspNetUsers>("Select * from AspNetUsers Where Id = @0", h.UserId);

                        if (i != null && i.DeviceToken != null)
                        {
                            string notificationtext = newvote + " " + i.UserName + " has voted for " + b.PostText;
                            CreatePushNotification(newvote, i.DeviceToken);
                        }
                    }
                }

                a.UserNotified = true;
                db2.Update(a);
            }
        }
コード例 #37
0
        private void NotifyStoryWinner()
        {
            var db = new PetaPoco.Database("AGSoftware");
            var db2 = new PetaPoco.Database("AGSoftware");
            var db3 = new PetaPoco.Database("AGSoftware");
            var db4 = new PetaPoco.Database("AGSoftware");

            foreach (var a in db.Query<Entities.Storytime>("select * from storytime s where (select count(*) from storytimeseries ss where ss.storytimeid = s.storytimeid) = 10 and s.UsersNotified = 0"))
            {
                var b = db2.SingleOrDefault<Entities.StoryWinner>("Select top 1 sum(sp.votes) as votes, u.username, s.storytimetitle from storytimeseries ss inner join storytimepost sp on ss.StorytimeSeriesId = sp.SeriesId inner join AspNetUsers u on u.id = sp.UserId inner join storytime s on s.storytimeid = ss.storytimeid where ss.storytimeid = @0 group by u.username, s.storytimetitle order by votes desc", a.StorytimeId);

                if (a.StorytimeTypeId == 1)
                {
                    var c = db2.SingleOrDefault<Entities.StorytimeGroup>("Select * from StorytimeGroup Where StorytimeId = @0", a.StorytimeId);
                    var d = db2.SingleOrDefault<Entities.UserGroup>("Select * from UserGroup Where UserGroupId = @0", c.UserGroupId);

                    foreach (var e in db3.Query<Entities.UserGroupUser>("Select * From UserGroupUser Where UserGroupId = @0", d.UserGroupId))
                    {
                        if (e != null)
                        {
                            var f = db4.SingleOrDefault<Entities.AspNetUsers>("Select * from AspNetUsers Where Id = @0", e.UserId);

                            if (f != null && f.DeviceToken != null)
                            {
                                CreatePushNotification(storywinner + f.UserName + " has won the story " + a.StorytimeTitle + " with " + b.Votes + " !", f.DeviceToken);
                            }
                        }
                    }
                }
                else if (a.StorytimeTypeId == 2)
                {
                    foreach (var g in db3.Query<Entities.StorytimeUserList>("Select * from StorytimeUserList Where StorytimeId = @0", a.StorytimeId))
                    {
                        var h = db4.SingleOrDefault<Entities.AspNetUsers>("Select * from AspNetUsers Where Id = @0", g.UserId);

                        if (h != null && h.DeviceToken != null)
                        {
                            CreatePushNotification(storywinner + h.UserName + " has won the story " + a.StorytimeTitle + " with " + b.Votes + " !", h.DeviceToken);
                        }
                    }
                }

                a.UsersNotified = true;
                db4.Update(a);
            }
        }
コード例 #38
0
ファイル: TestPeta.cs プロジェクト: refrom/ORMPerformanceTest
 private static int Update100Test(string connectionString)
 {
     var db = new PetaPoco.Database(connectionString, "System.Data.SqlClient");
     var homes = db.Query<Home>("SELECT * FROM home WHERE BuildYear=@0", 2014).ToList();
     int count = homes.Count();
     foreach (var home in homes)
     {
         if (home != null)
         {
             home.BuildYear = 2015;
             db.Update("Home", "Id", home);
         }
     }
     return count;
 }
コード例 #39
0
ファイル: ForumDataProvider.cs プロジェクト: ouyang90/XBBS
 public static Models.Forums GetForum(int id)
 {
     using (PetaPoco.Database db = new PetaPoco.Database("sqlconnection"))
     {
         var f = db.SingleOrDefault<Models.Forums>("WHERE fid=@0", id);
         if (f != null)
         {
             f.Views++;
             db.Update(f, new string[] { "views" });
         }
         return f;
     }
 }
コード例 #40
0
        private void NotifySeriesWinner()
        {
            var db = new PetaPoco.Database("AGSoftware");
            var db2 = new PetaPoco.Database("AGSoftware");
            var db3 = new PetaPoco.Database("AGSoftware");
            var db4 = new PetaPoco.Database("AGSoftware");

            foreach (var a in db.Query<Entities.SeriesWinner>("Select ss.StorytimeSeriesId, s.StorytimeTypeId, s.StorytimeId, s.StorytimeTitle, ss.SeriesText, u.Username, sp1.Votes From StorytimeSeries ss inner join Storytime s on s.StorytimeId = ss.StorytimeId inner join AspNetUsers u on ss.UserId = u.Id inner join StorytimePost sp1 on sp1.SeriesId = ss.StorytimeSeriesId And sp1.Votes = (Select MAX(sp2.Votes) From StorytimePost sp2 Where sp2.StorytimeId = sp1.StorytimeId) Where ss.UsersNotified = 0 And ss.DateCreated < DateAdd(hh, -24, GetDate())"))
            {
                if (a.StorytimeTypeId == 1)
                {
                    var b = db2.SingleOrDefault<Entities.StorytimeGroup>("Select * from StorytimeGroup Where StorytimeId = @0", a.StorytimeId);
                    var c = db2.SingleOrDefault<Entities.UserGroup>("Select * from UserGroup Where UserGroupId = @0", b.UserGroupId);

                    foreach (var d in db3.Query<Entities.UserGroupUser>("Select * From UserGroupUser Where UserGroupId = @0", c.UserGroupId))
                    {
                        if (d != null)
                        {
                            var e = db4.SingleOrDefault<Entities.AspNetUsers>("Select * from AspNetUsers Where Id = @0", d.UserId);

                            if (e != null && e.DeviceToken != null)
                            {
                                string notificationtext = string.Empty;
                                if (a.Votes > 0)
                                    notificationtext = serieswinner + " " + a.Username + " has won the series " + a.SeriesText + " for Story " + a.StorytimeTitle + " with " + a.Votes + " votes!";
                                else
                                    notificationtext = nowinner + a.SeriesText + " for Story " + a.StorytimeTitle;
                                CreatePushNotification(notificationtext, e.DeviceToken);
                            }
                        }
                    }
                }
                else if (a.StorytimeTypeId == 2)
                {
                    foreach (var f in db3.Query<Entities.StorytimeUserList>("Select * from StorytimeUserList Where StorytimeId = @0", a.StorytimeId))
                    {
                        var g = db4.SingleOrDefault<Entities.AspNetUsers>("Select * from AspNetUsers Where Id = @0", f.UserId);

                        if (g != null && g.DeviceToken != null)
                        {
                            string notificationtext = string.Empty;
                            if (a.Votes > 0)
                                notificationtext = serieswinner + " " + a.Username + " has won the series " + a.SeriesText + " for Story " + a.StorytimeTitle + " with " + a.Votes + " votes!";
                            else
                                notificationtext = nowinner + a.SeriesText + " for Story " + a.StorytimeTitle;
                            CreatePushNotification(notificationtext, g.DeviceToken);
                        }
                    }
                }

                var storytimeseries = db4.SingleOrDefault<Entities.StorytimeSeries>("Select * from StorytimeSeries Where StorytimeSeriesId = @0", a.StorytimeSeriesId);

                storytimeseries.UsersNotified = true;
                db4.Update(storytimeseries);

            }
        }
コード例 #41
0
ファイル: POST.ashx.cs プロジェクト: hurricanechaser/pindex
        private void fbLogin(HttpContext context)
        {
            string token = context.Request.Params["token"];
            Facebook.FacebookClient client = new Facebook.FacebookClient(token);
            //client.Post()
            client.UseFacebookBeta = client.IsSecureConnection = true;
            Facebook.JsonObject o = (Facebook.JsonObject)client.Get("/me");
            var db = new PetaPoco.Database(Common.HairStyleConnectionString, "System.Data.SqlClient");
            using (var scope = db.GetTransaction())
            {

                try
                {
                    string first_name = (string)o["first_name"];
                    string name = (string)o["name"];
                    decimal id = Convert.ToDecimal(o["id"]);
                    POCOS.Facebook fb = new POCOS.Facebook();
                    fb.name = name;
                    fb.first_name = first_name;
                    fb.gender = (string)o["gender"];
                    fb.id = id;
                    fb.last_name = (string)o["last_name"];
                    fb.link = (string)o["link"];
                    fb.locale = (string)o["locale"];
                    fb.timezone = Convert.ToDouble(o["timezone"]);
                    string updatedtime = (string)o["updated_time"];
                    DateTime dt;
                    if (DateTime.TryParse(updatedtime, out dt))
                        fb.updated_time = dt;
                    if (db.Exists<POCOS.Facebook>(id))
                        db.Update(fb);
                    else
                        db.Insert(fb);
                    POCOS.AppUser au = POCOS.AppUser.FirstOrDefault("Select top 1 * from AppUsers where facebookid=@0", id);
                    if (au == null)
                    {
                        au = new POCOS.AppUser();
                        au.FirstName = first_name;
                        au.facebookid = id;
                        db.Insert(au);
                    }
                    scope.Complete();
                    CookieUtil.WriteCookie(Common.AuthCookie, EncDec.Encrypt(JsonConvert.SerializeObject(new { ID = au.ID }), Common.DefaultPassword), false);
                    CookieUtil.WriteCookie(Common.InfoCookie, JsonConvert.SerializeObject(new { email = au.Email, name = au.Name, avatar = string.IsNullOrWhiteSpace(au.Avatar) ? null : Common.UploadedImageRelPath + au.Avatar }), false);
                }
                finally
                {
                    scope.Dispose();
                }
            }
        }
コード例 #42
0
        private void button3_Click(object sender, EventArgs e)
        {
            try
            {
                // Create a PetaPoco database object
                var db = new PetaPoco.Database("sqlite");

                // find the (presumably) most recently created foo
                int id = db.ExecuteScalar<int>("SELECT max(id) from foo");

                // Get a record
                var foo = db.SingleOrDefault<foo>("SELECT * FROM foo WHERE Id=@0", id);

                // Change it
                foo.name = "PetaPoco changed your name!";

                // Save it
                db.Update("foo", "Id", foo);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + Environment.NewLine + ex.StackTrace);
            }

            this.fooQuery1.Refresh();
        }