Пример #1
0
        public bool Update(long tid, BlogModuleModel tentity)
        {
            var success = false;

            if (tentity != null && tid != 0)
            {
                using (var scope = new TransactionScope())
                {
                    var oldrecord = _unitOfWork.BlogsRepository.GetByID(tid);
                    if (oldrecord != null)
                    {
                        oldrecord.blogdate        = tentity.blogdate;
                        oldrecord.blogdescription = tentity.blogdescription;
                        oldrecord.blogimage       = tentity.blogimage;
                        oldrecord.blogkeywords    = tentity.blogkeywords;
                        oldrecord.blogtags        = tentity.blogtags;
                        oldrecord.blogtitle       = tentity.blogtitle;
                        oldrecord.blogupdate      = tentity.blogupdate;
                        oldrecord.blogwebsite     = tentity.blogwebsite;
                        oldrecord.blogpublished   = tentity.blogpublished;

                        _unitOfWork.BlogsRepository.Update(oldrecord);
                        _unitOfWork.Save();
                        scope.Complete();
                        success = true;
                    }
                }
            }
            return(success);
        }
Пример #2
0
        public static BlogModuleModel BlogEntityMapper(ta_blog tentity)
        {
            var resultl = new BlogModuleModel
            {
                blogdate        = tentity.blogdate,
                blogdescription = tentity.blogdescription,
                blogid          = tentity.blogid,
                blogimage       = tentity.blogimage,
                blogkeywords    = tentity.blogkeywords,
                blogtags        = tentity.blogtags,
                blogtitle       = tentity.blogtitle,
                blogupdate      = tentity.blogupdate,
                blogwebsite     = tentity.blogwebsite,
                blogpublished   = tentity.blogpublished,
            };

            return(resultl);
        }
Пример #3
0
        public long Create(BlogModuleModel tentity)
        {
            using (var scope = new TransactionScope())
            {
                var NewRecord = new ta_blog
                {
                    blogdate        = tentity.blogdate,
                    blogdescription = tentity.blogdescription,
                    blogimage       = tentity.blogimage,
                    blogkeywords    = tentity.blogkeywords,
                    blogtags        = tentity.blogtags,
                    blogtitle       = tentity.blogtitle,
                    blogupdate      = tentity.blogupdate,
                    blogwebsite     = tentity.blogwebsite,
                    blogpublished   = tentity.blogpublished,
                };


                _unitOfWork.BlogsRepository.Insert(NewRecord);
                _unitOfWork.Save();
                scope.Complete();
                return(NewRecord.blogid);
            }
        }
Пример #4
0
        public ActionResult Save(BlogModuleModel input, string[] forwebsite, string[] blogtags)
        {
            bool status = false;


            if (ModelState.IsValid)
            {
                input.blogwebsite = forwebsite != null?StringArrayToString(forwebsite) : "Brick Kiln";

                input.blogtags = blogtags != null?StringArrayToString(blogtags) : null;

                var blogkeywordssanitized = SanitizeInput(input.blogkeywords);
                var blogfromdb            = _mainobj.GetByBlogNameKeyword(blogkeywordssanitized);
                if (input.blogid > 0)
                {
                    if (blogfromdb != null && blogfromdb.blogid != input.blogid)
                    {
                        return(new JsonResult {
                            Data = new { status = status, message = "Error! Url already existed." }
                        });
                    }

                    var olddata = _mainobj.GetById(input.blogid);
                    olddata.blogdescription = input.blogdescription;
                    olddata.blogdate        = input.blogdate;
                    olddata.blogkeywords    = blogkeywordssanitized;
                    olddata.blogtags        = input.blogtags;
                    olddata.blogtitle       = input.blogtitle;
                    olddata.blogupdate      = DateTime.Now;
                    olddata.blogwebsite     = input.blogwebsite;
                    olddata.blogpublished   = input.blogpublished;

                    //foreach (var item in input.blogtags.Split(','))
                    //{
                    //    olddata.tags
                    //}

                    var result = _mainobj.Update(input.blogid, olddata);
                }
                else
                {
                    input.blogkeywords = blogkeywordssanitized;
                    if (blogfromdb == null)
                    {
                        input.blogupdate    = DateTime.Now;
                        input.blogpublished = true;

                        var result = _mainobj.Create(input);
                    }
                    else
                    {
                        return(new JsonResult {
                            Data = new { status = status, message = "Error! Url already existed." }
                        });
                    }
                }
                status = true;
            }


            return(new JsonResult {
                Data = new { status = status }
            });
        }
Пример #5
0
        public ActionResult SaveImage(BlogModuleModel input)
        {
            bool status = false;

            try
            {
                if (ModelState.IsValid)
                {
                    if (input.blogid > 0)
                    {
                        var model = _mainobj.GetById(input.blogid);
                        if (Request.Files.Count > 0)
                        {
                            try
                            {
                                //  Get all files from Request object
                                HttpFileCollectionBase files = Request.Files;
                                for (int i = 0; i < files.Count; i++)
                                {
                                    HttpPostedFileBase file = files[i];
                                    string             fname;

                                    var checkresult = StaticData.CheckFile(file);
                                    if (checkresult != StaticData.ImageFileStatus.Success)
                                    {
                                        if (checkresult == StaticData.ImageFileStatus.NotFormat)
                                        {
                                            return new JsonResult {
                                                       Data = new { status = status, message = "Please add .jpg file only." }
                                            }
                                        }
                                        ;
                                        else if (checkresult == StaticData.ImageFileStatus.NotSize)
                                        {
                                            return new JsonResult {
                                                       Data = new { status = status, message = "Select file less than 2mb" }
                                            }
                                        }
                                        ;

                                        return(new JsonResult {
                                            Data = new { status = status, message = "An error occured." }
                                        });;
                                    }
                                    fname = StaticData.RandomData();
                                    // Get the complete folder path and store the file inside it.
                                    string path = Path.Combine(Server.MapPath("~/ReadWrite/"), Path.GetFileName(fname));
                                    path += ".jpg";
                                    file.SaveAs(path);
                                    ResizeImage(path, 550, 350);

                                    model.blogimage = fname;
                                    var result = _mainobj.Update(input.blogid, model);
                                }
                                status = true;
                            }
                            catch { }
                        }
                    }
                }
            }
            catch { }
            return(new JsonResult
            {
                Data = new { status = status, message = "File upload failed." }
            });
            //return RedirectToAction("Index");
        }