public ActionResult Authentication(String email, String title, String desc) { var check = (from user in db.UserTables where user.EmailAddress == email select user).SingleOrDefault(); if (check != null) { PostTable post = new PostTable(); post.Description = desc; post.PostedDate = DateTime.Now; post.Title = title; post.UserId = check.UserId; db.PostTables.Add(post); db.SaveChanges(); session.Message = "Record added. Thank you for your post!"; session.MessageCode = 1; } else { session.Message = "Sorry, invalid user e-mail!"; session.MessageCode = 0; } return RedirectToAction("Submission", "Home"); }
//GET: Submission and submits valid data public ActionResult Submission() { var postObj = new PostTable(); ViewBag.PostObj = postObj; if (session.Message != null) { ViewBag.ErrorMessage = session.Message; ViewBag.ErrorCode = session.MessageCode; } return View(); }
public JsonResult delIdea(int post_id) { DatabaseEntities db = new DatabaseEntities(); PostTable pt = db.PostTables.Where(r => r.post_Id == post_id).FirstOrDefault(); if (pt == null) { try { List <LikesTable> lt = db.LikesTables.Where(r => r.like_postID == post_id).ToList(); foreach (var v in lt) { db.LikesTables.Remove(v); } List <commentTable> ct = db.commentTables.Where(r => r.comment_postID == post_id).ToList(); foreach (var v in ct) { db.commentTables.Remove(v); } db.PostTables.Remove(db.PostTables.Find(post_id)); db.SaveChanges(); var json1 = new { success = "ok" }; return(Json(json1)); } catch (Exception e) { var json2 = new { success = e }; return(Json(json2)); } } else { var json = new { success = "not" }; return(Json(json)); } }
public void RightOuterJoin() { var u = new UserTable(); var p = new PostTable(); var q = new SharpQuery(); q.Select(u.FirstName, p.Title).From(u).RightOuterJoin(p, p.UserId.IsEqualTo(u.Id)).EndStatement(); var script = q.ToString(); TSqlAssert.ScriptsAreEqual(script, @" SELECT [dbo].[User].[Name] , [dbo].[Post].[Title]FROM [dbo].[User]RIGHT OUTER JOIN [dbo].[Post] ON [dbo].[Post].[UserId] = [dbo].[User].[Id] "); }
public void AddPost(PostTable post) { int active = 0; if (post.Active) { active = 1; } BlogDatabase.Execute ("INSERT INTO POSTS (Author, Title, Content, Active) " + "VALUES (@author, @title, @content, @active)", new { @author = post.Author, @title = post.Title, @content = post.Content, active }); }
public ActionResult saveIdea(PostTable obj) { if (Session["UserID"] != null) { int a = (int)System.Web.HttpContext.Current.Session["UserID"]; DatabaseEntities db = new DatabaseEntities(); UserTable obj1 = new UserTable(); obj1 = db.UserTables.Where(x => x.user_Id == a).FirstOrDefault(); obj.post_userID = a; PostTable b = db.PostTables.Add(obj); db.SaveChanges(); return(View("postIdea")); } else { return(View("error")); } }
public ViewPost(PostTable postTable) { if (postTable is null) { throw new ArgumentNullException(nameof(postTable)); } Id = postTable.Id; Author = postTable.Author; Title = postTable.Title; if (postTable.Content?.Length > 150) { ShortContent = postTable.Content?.Substring(0, 150); } else { ShortContent = postTable.Content; } Content = postTable.Content; Active = postTable.Active; }
public PostTable ToPostFrom(PostModel from) { var post = new PostTable(); post.Desription = from.Desription; post.Id = from.Id; post.DateCreated = from.DateCreated; post.Image = from.Image; from.Comments.ForEach(x => post.Comments?.Add(ToCommentFrom(x))); if (from.Likes == null) { from.Likes = new List <LikeModel> (); } foreach (var like in from.Likes) { post.Likes.Add(ToLikeFrom(like)); } return(post); }
public ActionResult EditIdea(int id) { DatabaseEntities db = new DatabaseEntities(); PostTable obj = db.PostTables.Find(id); ideaDetail data = new ideaDetail(); data.postData = obj; data.userData = db.UserTables.Where(r => r.user_Id == obj.post_userID).FirstOrDefault(); List <commentTable> comment = db.commentTables.Where(r => r.comment_postID == obj.post_Id).ToList(); List <commentDetail> cmList = new List <commentDetail>(); foreach (var a in comment) { commentDetail cmntdetail = new commentDetail(); cmntdetail.cmnt = a; cmntdetail.user = db.UserTables.Find(a.comment_userID); cmList.Add(cmntdetail); } data.commentData = cmList; data.likeData = db.LikesTables.Where(r => r.like_postID == obj.post_Id).ToList(); return(View(data)); }
public void Test1() { var q = new SharpQuery(); var u = new UserTable(); var p = new PostTable(); q.Select(u.Id, Sql.Count(1)) .From(u) .InnerJoin(p, p.UserId.IsEqualTo(u.Id)) .GroupBy(u.Id) .EndStatement(); var query = q.ToString(); TSqlAssert.ScriptsAreEqual(query, @" SELECT [dbo].[User].[Id] , COUNT( @p0 ) FROM [dbo].[User] INNER JOIN [dbo].[Post] ON [dbo].[Post].[UserId] = [dbo].[User].[Id] GROUP BY [dbo].[User].[Id]"); }
public void Update(PostTable value) { var prev = _updatePosts.SingleOrDefault(p => p.Login.Equals(value.Login) && p.Permlink.Equals(value.Permlink)); if (prev != null) { if (value.CompareTo(prev) > 0) { prev.Title = value.Title; prev.JsonData = value.JsonData; prev.Body = value.Body; } else { prev.Timestamp = value.Timestamp; } } else { _updatePosts.Add(value); Interlocked.Increment(ref Count); } }
public PostModel ToPostModelFrom(PostTable from) { var post = new PostModel(); post.Comments = new List <CommentModel> (); post.Likes = new List <LikeModel> (); post.IsLiked = CurrentUser.User?.LikedPosts?.FirstOrDefault(x => x?.Post?.Id == post.Id) != null; post.IsSaved = CurrentUser.User?.SavedPosts?.FirstOrDefault(x => x?.Post?.Id == post.Id) != null; post.Desription = from.Desription; post.Id = from.Id; post.DateCreated = from.DateCreated; post.Image = from.Image; from.Comments?.ForEach(x => post.Comments?.Add(ToCommentModelFrom(x))); from.Comments?.ForEach(x => post.Comments?.Add(ToCommentModelFrom(x))); from.Likes?.ForEach(x => post.Likes?.Add(ToLikeModelFrom(x))); post.Comments?.OrderBy(comment => comment.DateCreated); return(post); }
internal Typeface ReadTableEntryCollection(TableEntryCollection tables, BinaryReader input) { OS2Table os2Table = ReadTableIfExists(tables, input, new OS2Table()); NameEntry nameEntry = ReadTableIfExists(tables, input, new NameEntry()); Head header = ReadTableIfExists(tables, input, new Head()); MaxProfile maximumProfile = ReadTableIfExists(tables, input, new MaxProfile()); HorizontalHeader horizontalHeader = ReadTableIfExists(tables, input, new HorizontalHeader()); HorizontalMetrics horizontalMetrics = ReadTableIfExists(tables, input, new HorizontalMetrics(horizontalHeader.HorizontalMetricsCount, maximumProfile.GlyphCount)); //--- PostTable postTable = ReadTableIfExists(tables, input, new PostTable()); CFFTable ccf = ReadTableIfExists(tables, input, new CFFTable()); //-------------- Cmap cmaps = ReadTableIfExists(tables, input, new Cmap()); GlyphLocations glyphLocations = ReadTableIfExists(tables, input, new GlyphLocations(maximumProfile.GlyphCount, header.WideGlyphLocations)); Glyf glyf = ReadTableIfExists(tables, input, new Glyf(glyphLocations)); //-------------- Gasp gaspTable = ReadTableIfExists(tables, input, new Gasp()); VerticalDeviceMetrics vdmx = ReadTableIfExists(tables, input, new VerticalDeviceMetrics()); //-------------- Kern kern = ReadTableIfExists(tables, input, new Kern()); //-------------- //advanced typography GDEF gdef = ReadTableIfExists(tables, input, new GDEF()); GSUB gsub = ReadTableIfExists(tables, input, new GSUB()); GPOS gpos = ReadTableIfExists(tables, input, new GPOS()); BASE baseTable = ReadTableIfExists(tables, input, new BASE()); COLR colr = ReadTableIfExists(tables, input, new COLR()); CPAL cpal = ReadTableIfExists(tables, input, new CPAL()); VerticalHeader vhea = ReadTableIfExists(tables, input, new VerticalHeader()); if (vhea != null) { VerticalMetrics vmtx = ReadTableIfExists(tables, input, new VerticalMetrics(vhea.NumOfLongVerMetrics)); } //test math table MathTable mathtable = ReadTableIfExists(tables, input, new MathTable()); EBLCTable fontBmpTable = ReadTableIfExists(tables, input, new EBLCTable()); //--------------------------------------------- //about truetype instruction init //--------------------------------------------- Typeface typeface = null; bool isPostScriptOutline = false; if (glyf == null) { //check if this is cff table ? if (ccf == null) { //TODO: review here throw new NotSupportedException(); } //... //PostScript outline font isPostScriptOutline = true; typeface = new Typeface( nameEntry, header.Bounds, header.UnitsPerEm, ccf, horizontalMetrics, os2Table); } else { typeface = new Typeface( nameEntry, header.Bounds, header.UnitsPerEm, glyf.Glyphs, horizontalMetrics, os2Table); } //---------------------------- typeface.CmapTable = cmaps; typeface.KernTable = kern; typeface.GaspTable = gaspTable; typeface.MaxProfile = maximumProfile; typeface.HheaTable = horizontalHeader; //---------------------------- if (!isPostScriptOutline) { FpgmTable fpgmTable = ReadTableIfExists(tables, input, new FpgmTable()); //control values table CvtTable cvtTable = ReadTableIfExists(tables, input, new CvtTable()); if (cvtTable != null) { typeface.ControlValues = cvtTable._controlValues; } if (fpgmTable != null) { typeface.FpgmProgramBuffer = fpgmTable._programBuffer; } PrepTable propProgramTable = ReadTableIfExists(tables, input, new PrepTable()); if (propProgramTable != null) { typeface.PrepProgramBuffer = propProgramTable._programBuffer; } } //------------------------- typeface.LoadOpenFontLayoutInfo( gdef, gsub, gpos, baseTable, colr, cpal); //------------ //test { SvgTable svgTable = ReadTableIfExists(tables, input, new SvgTable()); if (svgTable != null) { typeface._svgTable = svgTable; } } typeface.PostTable = postTable; if (mathtable != null) { var mathGlyphLoader = new MathGlyphLoader(); mathGlyphLoader.LoadMathGlyph(typeface, mathtable); } #if DEBUG //test //int found = typeface.GetGlyphIndexByName("Uacute"); if (typeface.IsCffFont) { //optional typeface.UpdateAllCffGlyphBounds(); } #endif return(typeface); }
public TtfTypeface Read(Stream stream, ReadFlags readFlags = ReadFlags.Full) { var little = BitConverter.IsLittleEndian; using (var input = new ByteOrderSwappingBinaryReader(stream)) { ushort majorVersion = input.ReadUInt16(); ushort minorVersion = input.ReadUInt16(); ushort tableCount = input.ReadUInt16(); ushort searchRange = input.ReadUInt16(); ushort entrySelector = input.ReadUInt16(); ushort rangeShift = input.ReadUInt16(); var tables = new TableEntryCollection(); for (int i = 0; i < tableCount; i++) { tables.AddEntry(new UnreadTableEntry(ReadTableHeader(input))); } //------------------------------------------------------------------ OS2Table os2Table = ReadTableIfExists(tables, input, new OS2Table()); NameEntry nameEntry = ReadTableIfExists(tables, input, new NameEntry()); Head header = ReadTableIfExists(tables, input, new Head()); MaxProfile maximumProfile = ReadTableIfExists(tables, input, new MaxProfile()); HorizontalHeader horizontalHeader = ReadTableIfExists(tables, input, new HorizontalHeader()); HorizontalMetrics horizontalMetrics = ReadTableIfExists(tables, input, new HorizontalMetrics(horizontalHeader.HorizontalMetricsCount, maximumProfile.GlyphCount)); //-------------- Cmap cmaps = ReadTableIfExists(tables, input, new Cmap()); GlyphLocations glyphLocations = ReadTableIfExists(tables, input, new GlyphLocations(maximumProfile.GlyphCount, header.WideGlyphLocations)); Glyf glyf = ReadTableIfExists(tables, input, new Glyf(glyphLocations)); //-------------- Gasp gaspTable = ReadTableIfExists(tables, input, new Gasp()); VerticalDeviceMetrics vdmx = ReadTableIfExists(tables, input, new VerticalDeviceMetrics()); //-------------- PostTable postTable = ReadTableIfExists(tables, input, new PostTable()); Kern kern = ReadTableIfExists(tables, input, new Kern()); //-------------- //advanced typography GDEF gdef = ReadTableIfExists(tables, input, new GDEF()); GSUB gsub = ReadTableIfExists(tables, input, new GSUB()); GPOS gpos = ReadTableIfExists(tables, input, new GPOS()); BASE baseTable = ReadTableIfExists(tables, input, new BASE()); COLR colr = ReadTableIfExists(tables, input, new COLR()); CPAL cpal = ReadTableIfExists(tables, input, new CPAL()); VerticalHeader vhea = ReadTableIfExists(tables, input, new VerticalHeader()); if (vhea != null) { VerticalMatric vmtx = ReadTableIfExists(tables, input, new VerticalMatric(vhea.NumOfLongVerMetrics)); } EBLCTable fontBmpTable = ReadTableIfExists(tables, input, new EBLCTable()); //--------------------------------------------- //about truetype instruction init //--------------------------------------------- var typeface = new TtfTypeface( nameEntry, header.Bounds, header.UnitsPerEm, glyf.Glyphs, horizontalMetrics, os2Table); //---------------------------- typeface.CmapTable = cmaps; typeface.KernTable = kern; typeface.GaspTable = gaspTable; typeface.MaxProfile = maximumProfile; typeface.HheaTable = horizontalHeader; //---------------------------- FpgmTable fpgmTable = ReadTableIfExists(tables, input, new FpgmTable()); //control values table CvtTable cvtTable = ReadTableIfExists(tables, input, new CvtTable()); if (cvtTable != null) { typeface.ControlValues = cvtTable.controlValues; } if (fpgmTable != null) { typeface.FpgmProgramBuffer = fpgmTable.programBuffer; } PrepTable propProgramTable = ReadTableIfExists(tables, input, new PrepTable()); if (propProgramTable != null) { typeface.PrepProgramBuffer = propProgramTable.programBuffer; } //------------------------- typeface.LoadOpenFontLayoutInfo( gdef, gsub, gpos, baseTable, colr, cpal); return(typeface); } }
public IActionResult Privacy(PostTable P) { ORM.PostTable.Add(P); ORM.SaveChanges(); return(View()); }
internal bool ReadTableEntryCollection(Typeface typeface, RestoreTicket ticket, TableEntryCollection tables, BinaryReader input) { if (ticket != null) { return(ReadTableEntryCollectionOnRestoreMode(typeface, ticket, tables, input)); } typeface.SetTableEntryCollection(tables.CloneTableHeaders()); var rd = new EntriesReaderHelper(tables, input); //PART 1: basic information OS2Table os2Table = rd.Read(new OS2Table()); Meta meta = rd.Read(new Meta()); NameEntry nameEntry = rd.Read(new NameEntry()); Head head = rd.Read(new Head()); MaxProfile maxProfile = rd.Read(new MaxProfile()); HorizontalHeader horizontalHeader = rd.Read(new HorizontalHeader()); HorizontalMetrics horizontalMetrics = rd.Read(new HorizontalMetrics(horizontalHeader.NumberOfHMetrics, maxProfile.GlyphCount)); VerticalHeader vhea = rd.Read(new VerticalHeader()); if (vhea != null) { VerticalMetrics vmtx = rd.Read(new VerticalMetrics(vhea.NumOfLongVerMetrics)); } Cmap cmaps = rd.Read(new Cmap()); VerticalDeviceMetrics vdmx = rd.Read(new VerticalDeviceMetrics()); Kern kern = rd.Read(new Kern()); //------------------------------------ //PART 2: glyphs detail //2.1 True type font GlyphLocations glyphLocations = rd.Read(new GlyphLocations(maxProfile.GlyphCount, head.WideGlyphLocations)); Glyf glyf = rd.Read(new Glyf(glyphLocations)); Gasp gaspTable = rd.Read(new Gasp()); COLR colr = rd.Read(new COLR()); CPAL cpal = rd.Read(new CPAL()); //2.2 Cff font PostTable postTable = rd.Read(new PostTable()); CFFTable cff = rd.Read(new CFFTable()); //additional math table (if available) MathTable mathtable = rd.Read(new MathTable()); //------------------------------------ //PART 3: advanced typography GDEF gdef = rd.Read(new GDEF()); GSUB gsub = rd.Read(new GSUB()); GPOS gpos = rd.Read(new GPOS()); BASE baseTable = rd.Read(new BASE()); JSTF jstf = rd.Read(new JSTF()); STAT stat = rd.Read(new STAT()); if (stat != null) { //variable font FVar fvar = rd.Read(new FVar()); if (fvar != null) { GVar gvar = rd.Read(new GVar()); CVar cvar = rd.Read(new CVar()); HVar hvar = rd.Read(new HVar()); MVar mvar = rd.Read(new MVar()); AVar avar = rd.Read(new AVar()); } } bool isPostScriptOutline = false; bool isBitmapFont = false; typeface.SetBasicTypefaceTables(os2Table, nameEntry, head, horizontalMetrics); if (glyf == null) { //check if this is cff table ? if (cff == null) { //check cbdt/cblc ? CBLC cblcTable = rd.Read(new CBLC()); if (cblcTable != null) { CBDT cbdtTable = rd.Read(new CBDT()); //read cbdt //bitmap font BitmapFontGlyphSource bmpFontGlyphSrc = new BitmapFontGlyphSource(cblcTable); bmpFontGlyphSrc.LoadCBDT(cbdtTable); Glyph[] glyphs = bmpFontGlyphSrc.BuildGlyphList(); typeface.SetBitmapGlyphs(glyphs, bmpFontGlyphSrc); isBitmapFont = true; } else { //TODO: EBLC fontBmpTable = rd.Read(new EBLC()); throw new NotSupportedException(); } } else { isPostScriptOutline = true; typeface.SetCffFontSet(cff.Cff1FontSet); } } else { typeface.SetTtfGlyphs(glyf.Glyphs); } //---------------------------- typeface.CmapTable = cmaps; typeface.KernTable = kern; typeface.MaxProfile = maxProfile; typeface.HheaTable = horizontalHeader; //---------------------------- typeface.GaspTable = gaspTable; if (!isPostScriptOutline && !isBitmapFont) { //for true-type font outline FpgmTable fpgmTable = rd.Read(new FpgmTable()); //control values table CvtTable cvtTable = rd.Read(new CvtTable()); PrepTable propProgramTable = rd.Read(new PrepTable()); typeface.ControlValues = cvtTable?._controlValues; typeface.FpgmProgramBuffer = fpgmTable?._programBuffer; typeface.PrepProgramBuffer = propProgramTable?._programBuffer; } //------------------------- typeface.LoadOpenFontLayoutInfo( gdef, gsub, gpos, baseTable, colr, cpal); //------------ typeface.SetSvgTable(rd.Read(new SvgTable())); typeface.PostTable = postTable; if (mathtable != null) { MathGlyphLoader.LoadMathGlyph(typeface, mathtable); } #if DEBUG //test //int found = typeface.GetGlyphIndexByName("Uacute"); if (typeface.IsCffFont) { //optional typeface.UpdateAllCffGlyphBounds(); } #endif typeface.UpdateLangs(meta); typeface.UpdateFrequentlyUsedValues(); return(true); }
public OpenTypeFont Deserialize(BinaryReader reader) { var font = new OpenTypeFont { SfntVersion = DataTypeConverter.ReadFixed(reader) }; if (!_supportedSfntVersions.Contains(font.SfntVersion)) { throw new NotSupportedException("Bad sfnt version."); } // Table directory var numberOfTables = DataTypeConverter.ReadUShort(reader); reader.BaseStream.Position += 3 * DataTypeLength.UShort; // searchRange, entrySelector, rangeShift var entryList = Enumerable.Range(0, numberOfTables).Select(i => { var entry = new TableDirectoryEntry { Tag = DataTypeConverter.ReadTag(reader) }; reader.BaseStream.Position += DataTypeLength.ULong; // checksum entry.Offset = DataTypeConverter.ReadULong(reader); entry.Length = DataTypeConverter.ReadULong(reader); return(entry); }).ToList(); // Tables font.Tables.AddRange( entryList.OrderBy(entry => entry.Priority).Select <TableDirectoryEntry, IOpenTypeFontTable>(entry => { switch (entry.Tag) { case "cmap": return(CmapTable.Deserialize(reader, entry.Offset)); case "head": return(HeadTable.Deserialize(reader, entry.Offset)); case "maxp": return(MaxpTable.Deserialize(reader, entry.Offset)); case "loca": return(LocaTable.Deserialize(reader, entry.Offset, font.Get <MaxpTable>().NumberOfGlyphs, font.Get <HeadTable>().LocaTableVersion)); case "glyf": return(GlyfTable.Deserialize(reader, entry.Offset, entry.Length, font.Get <LocaTable>())); case "hhea": return(HheaTable.Deserialize(reader, entry.Offset)); case "hmtx": return(HmtxTable.Deserialize(reader, entry.Offset, font.Get <HheaTable>().NumberOfHMetrics, font.Get <MaxpTable>().NumberOfGlyphs)); case "post": return(PostTable.Deserialize(reader, entry.Offset)); default: return(BinaryDataTable.Deserialize(reader, entry.Offset, entry.Length, entry.Tag)); } })); return(font); }