Ejemplo n.º 1
0
        public string Post(RefItem refItem)
        {
            string success = "";

            try
            {
                using (WebSiteContext db = new WebSiteContext())
                {
                    Ref @ref = new Ref();
                    @ref.RefType        = refItem.RefType;
                    @ref.RefCode        = GetUniqueRefCode(refItem.RefDescription, db);
                    @ref.RefDescription = refItem.RefDescription;

                    db.Refs.Add(@ref);
                    db.SaveChanges();

                    //refModel.RefCode = @ref.RefCode;
                    success = "ok";
                }
            }
            catch (Exception ex)
            {
                success = ex.Message;
            }
            return(success);
        }
Ejemplo n.º 2
0
        public string Put(Comment updateComment)
        {
            string success = "";

            try
            {
                using (WebSiteContext db = new WebSiteContext())
                {
                    Comment comment = db.Comments.Where(c => c.CommentId == updateComment.CommentId).FirstOrDefault();
                    if (comment != null)
                    {
                        comment.CommentText  = updateComment.CommentText;
                        comment.CommentTitle = updateComment.CommentTitle;

                        db.SaveChanges();
                        success = "ok";
                    }
                    else
                    {
                        success = "comment not found";
                    }
                }
            }
            catch (Exception ex)
            {
                success = Helpers.ErrorDetails(ex);
            }
            return(success);
        }
Ejemplo n.º 3
0
        public CommentsModel Post(CommentsModel newComment)
        {
            try
            {
                using (WebSiteContext db = new WebSiteContext())
                {
                    var comment = new Comment();
                    comment.CreateDate   = DateTime.Now;
                    comment.ArticleId    = newComment.ArticleId;
                    comment.CommentText  = newComment.CommentText;
                    comment.CommentTitle = newComment.CommentTitle;
                    comment.UserId       = newComment.UserId;
                    comment.UserName     = newComment.UserName;
                    db.Comments.Add(comment);
                    db.SaveChanges();

                    newComment.CommentId  = comment.CommentId;
                    newComment.CreateDate = comment.CreateDate.ToShortDateString();
                    newComment.success    = "ok";

                    //newComment.success = new GodaddyEmailController().SendEmail("Somebody Actually Made A comment", comment.UserName + " said: " + comment.CommentText);
                }
            }
            catch (Exception ex)
            {
                newComment.success = Helpers.ErrorDetails(ex);
            }
            return(newComment);
        }
Ejemplo n.º 4
0
        public string UpdateArticle(VwArticle articleModel)
        {
            var success = "";

            try
            {
                using (WebSiteContext db = new WebSiteContext())
                {
                    Article updateArticle = db.Articles.Where(a => a.Id.ToString() == articleModel.Id).FirstOrDefault();
                    updateArticle.Title          = articleModel.Title;
                    updateArticle.CategoryRef    = articleModel.CategoryRef;
                    updateArticle.SubCategoryRef = articleModel.SubCategoryRef;
                    updateArticle.ImageName      = articleModel.ImageName;
                    updateArticle.LastUpdated    = articleModel.LastUpdated; //DateTime.Now;
                    updateArticle.ByLineRef      = articleModel.ByLineRef;
                    updateArticle.Content        = articleModel.Content;
                    updateArticle.Summary        = articleModel.Summary;

                    //db.ArticleTags.RemoveRange(db.ArticleTags.Where(t => t.articleId.ToString() == editArticle.Id));
                    ////article.ArticleTags = null;
                    //foreach (DbArticleTagModel tagModel in editArticle.Tags)
                    //{
                    //    article.ArticleTags.Add(new ArticleTag() { articleId = article.Id, Id = tagModel.Id, TagName = tagModel.TagName });
                    //}

                    db.SaveChanges();
                    success = "ok";
                }
            }
            catch (Exception ex) { success = Helpers.ErrorDetails(ex); }
            return(success);
        }
Ejemplo n.º 5
0
        public SuccessModel AddImage(ImageData data)
        {
            var successModel = new SuccessModel();

            try
            {
                // data:image/jpeg;base64,
                string imageFullFileName = Path.Combine(imagesPath, data.FileName);

                string trimData = data.Data.ToString().Substring(23);

                byte[] byteArray = Convert.FromBase64String(trimData);
                //Byte[] byteArray = data.Data.ReadAsByteArrayAsync().Result;
                File.WriteAllBytes(imageFullFileName, byteArray);

                // USE WEBREQUEST TO UPLOAD THE FILE
                FtpWebRequest webRequest = null;
                string        destPath   = ftpHost + articleImagesFolder;

                if (!FtpUtilies.DirectoryExists(destPath))
                {
                    FtpUtilies.CreateDirectory(destPath);
                }

                webRequest             = (FtpWebRequest)WebRequest.Create(destPath + "/" + data.FileName);
                webRequest.Credentials = networkCredentials;
                webRequest.Method      = WebRequestMethods.Ftp.UploadFile;

                using (Stream requestStream = webRequest.GetRequestStream())
                {
                    byte[] fileContents = System.IO.File.ReadAllBytes(imageFullFileName);
                    webRequest.ContentLength = fileContents.Length;
                    requestStream.Write(fileContents, 0, fileContents.Length);
                    requestStream.Flush();
                    requestStream.Close();
                }

                using (WebSiteContext db = new WebSiteContext())
                {
                    Article article = db.Articles.Where(a => a.Id == data.ArticleId).FirstOrDefault();
                    article.ImageName = data.FileName;
                    db.SaveChanges();
                    successModel.ReturnValue = data.FileName;
                }
                successModel.Success = "ok";
            }
            catch (Exception ex)
            {
                successModel.Success = Helpers.ErrorDetails(ex);
            }
            return(successModel);
        }
Ejemplo n.º 6
0
        public string Put(RefItem refItem)
        {
            string success = "";

            try
            {
                using (WebSiteContext db = new WebSiteContext())
                {
                    Ref @ref = db.Refs.Where(r => r.RefCode == refItem.RefCode).First();
                    @ref.RefDescription = refItem.RefDescription;
                    db.SaveChanges();
                    success = "ok";
                }
            }
            catch (Exception ex) { success = ex.Message; }
            return(success);
        }
Ejemplo n.º 7
0
        public string Post(DbArticleTagModel tag)
        {
            var success = "";

            try
            {
                var dbTag = new ArticleTag();
                dbTag.TagName   = tag.TagName;
                dbTag.articleId = tag.ArticleId;
                using (WebSiteContext db = new WebSiteContext())
                {
                    db.ArticleTags.Add(dbTag);
                    db.SaveChanges();
                    success = "ok";
                }
            }
            catch (Exception ex) { success = Helpers.ErrorDetails(ex); }
            return(success);
        }
Ejemplo n.º 8
0
        public string AddNewArticle(VwArticle articleModel)
        {
            string success;

            try
            {
                Article newArticle = new Article
                {
                    //Id = Guid.NewGuid().ToString(),
                    Id             = articleModel.Id,
                    Title          = articleModel.Title,
                    CategoryRef    = articleModel.CategoryRef,
                    SubCategoryRef = articleModel.SubCategoryRef,
                    ImageName      = articleModel.ImageName,
                    Created        = DateTime.Now,
                    LastUpdated    = DateTime.Now,
                    Content        = articleModel.Content,
                    Summary        = articleModel.Summary,
                    ByLineRef      = articleModel.ByLineRef
                };

                //foreach (DbArticleTagModel tag in articleModel.Tags)
                //    if (tag.TagName != null)
                //        newArticle.ArticleTags.Add(new ArticleTag() { TagName = tag.TagName, TagCategoryRef = tag.TagCategoryRef });
                using (WebSiteContext db = new WebSiteContext())
                {
                    db.Articles.Add(newArticle);
                    db.SaveChanges();
                    success = "ok";
                }
            }
            catch (Exception ex)
            {
                success = Helpers.ErrorDetails(ex);
            }
            return(success);
        }