NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

[HttpPost]
public JsonResult SaveNews(NewsModel _NewsModel)
{
int _return = 0;
try
{
if (_NewsModel.NewsId == 0)
{
if (_NewsModel.HasImage == true)
{

var TemporaryPath = new DirectoryInfo(string.Format("{0}Images\Temp", Server.MapPath(@""))).ToString();
bool isTempDirExists = System.IO.Directory.Exists(TemporaryPath);
if (!isTempDirExists)
System.IO.Directory.CreateDirectory(TemporaryPath);

var TempSavingPath = string.Format("{0}\{1}", TemporaryPath, _NewsModel.ImageName);
//isFileExists = System.IO.File.Exists(TempSavingPath);
/// SAving file in temp FOLDER
var isFileExists = System.IO.File.Exists(TempSavingPath);

var HeadPath = new DirectoryInfo(string.Format("{0}Images\Uploaded", Server.MapPath(@""))).ToString();

var HeadsavingPath = string.Format("{0}\{1}{2}", HeadPath, Guid.NewGuid().ToString().Substring(0, 10), (_NewsModel.extension == null ? ".jpg" : _NewsModel.extension));

bool isDirExists = System.IO.Directory.Exists(HeadPath);
if (!isDirExists)
System.IO.Directory.CreateDirectory(HeadPath);

System.IO.File.Copy(TempSavingPath, HeadsavingPath, true);
System.IO.File.Delete(TempSavingPath);
}
else
{
//var TemporaryPath = new DirectoryInfo(string.Format("{0}Images\Temp", Server.MapPath(@""))).ToString();
//bool isTempDirExists = System.IO.Directory.Exists(TemporaryPath);
//if (!isTempDirExists)
// System.IO.Directory.CreateDirectory(TemporaryPath);

//var TempSavingPath = string.Format("{0}\{1}", TemporaryPath, _NewsModel.ImageName);
////isFileExists = System.IO.File.Exists(TempSavingPath);
///// SAving file in temp FOLDER
//var isFileExists = System.IO.File.Exists(TempSavingPath);

//var HeadPath = new DirectoryInfo(string.Format("{0}Images\Uploaded", Server.MapPath(@""))).ToString();
//var HeadsavingPath = string.Format("{0}\{1}{2}", HeadPath, _NewsModel.shortDesc, ".jpg");

//bool isDirExists = System.IO.Directory.Exists(HeadPath);
//if (!isDirExists)
// System.IO.Directory.CreateDirectory(HeadPath);

//System.IO.File.Copy(TempSavingPath, HeadsavingPath, true);
}
}
else if (_NewsModel.NewsId != 0)
{
//var Template = TemplateManager.GetTemplateById(_NewsModel.NewsId);
var HeadPath = new DirectoryInfo(string.Format("{0}Images\Uploaded", Server.MapPath(@""))).ToString();

var TemporaryDirPath = new DirectoryInfo(string.Format("{0}Images\Temp", Server.MapPath(@""))).ToString();
var TempSavedFilePath = string.Format("{0}\{1}", TemporaryDirPath, _NewsModel.ImageName);
bool isTempFileExists = System.IO.File.Exists(TempSavedFilePath);
News news = context.News.Where(n => n.NewsId == _NewsModel.NewsId).FirstOrDefault();

var ImageNameEarlier = news.ImageName;


if (news != null)
{
news.shortDesc = _NewsModel.shortDesc;
news.Headline = _NewsModel.Headline;
news.Desc = _NewsModel.Desc;
news.HasImage = _NewsModel.HasImage;
news.ModifiedBy = 1;
news.ModifiedDate = DateTime.Now;

context.SaveChanges();


if (_NewsModel.ImageName != ImageNameEarlier)
{
/// name of the image changed & file exists
if (_NewsModel.HasImage || _NewsModel.ImageName != null)
{
if (isTempFileExists)
{
var NewSavingFilePath = string.Format("{0}\{1}", HeadPath, news.ImageName);

System.IO.File.Copy(TempSavedFilePath, NewSavingFilePath, true);

///Deleting temp file after changes
if (System.IO.File.Exists(NewSavingFilePath))
{
System.IO.File.Delete(TempSavedFilePath);
}
}
}
/// name of the image changed & file deleted
else if (_NewsModel.HasImage == false)
{
var HeadSavedFilePath = string.Format("{0}\{1}", HeadPath, ImageNameEarlier);

///Deleting temp file after changes
if (System.IO.File.Exists(HeadSavedFilePath))
{
System.IO.File.Delete(HeadSavedFilePath);
}
}
}
}
else
{
_return = -1;
//CustomLogger.LogError.GetLogger.Log(ex, "Error in AddTemplate Function");
}
}
if (SaveNewsDb(_NewsModel))
{
_return = 1;
}
}
catch (Exception ex)
{
//CustomLogger.LogError.GetLogger.Log(ex, "Error in AddTemplate Function");
_return = -1;
}
return Json(_return, JsonRequestBehavior.AllowGet);
}



[HttpGet]
public JsonResult GetNewsById()
{
NewsModel newsModel = null;
try
{
var news = this.GetNewsFromDb(1);
if (news != null)
{
newsModel = new NewsModel();
newsModel.NewsId = news.NewsId;
newsModel.Headline = news.Headline;
newsModel.shortDesc = news.shortDesc;
newsModel.Desc = news.Desc;
newsModel.HasImage = newsModel.HasImage;
newsModel.ImageName = newsModel.ImageName;
}
}
catch (Exception ex)
{
//CustomLogger.LogError.GetLogger.Log(ex, "Error in GetNewsById Function");
return Json("-1", JsonRequestBehavior.AllowGet);
}
return Json(newsModel, JsonRequestBehavior.AllowGet);
}

private News GetNewsFromDb(int NewsId)
{
News news = null;
try
{
news = context.News.Where(x => x.NewsId == NewsId).FirstOrDefault();
}
catch (Exception ex)
{
throw;
}
return news;
}
[HttpGet]
public JsonResult DeleteNewsById()
{
var _return = -1;
try
{
int NewsId = 1;
using (EntityModel context = new EntityModel())
{
var news = context.News.Where(x => x.NewsId == NewsId).FirstOrDefault();

if (news != null)
{
news.IsDeleted = true;
news.DeletedBy = 1;
news.DeletedDate = DateTime.Now;

context.SaveChanges();
_return = 1;
}
}

}
catch (Exception ex)
{
//CustomLogger.LogError.GetLogger.Log(ex, "Error in GetNewsById Function");
return Json("-1", JsonRequestBehavior.AllowGet);
}
return Json(_return, JsonRequestBehavior.AllowGet);
}







     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.