public int CreateEmptyEvent()
 {
     var eventNew = new Event
     {
         TypeId = 1,
         DateCreate = DateTime.Now,
         TranslitUrl = Guid.NewGuid().ToString()
     };
     _context.Events.Add(eventNew);
     _context.SaveChanges();
     eventNew.Title = string.Format("Нова подія #: {0}", eventNew.EventId);
     _context.SaveChanges();
     return eventNew.EventId;
 }
 public bool SaveEvent(Event eventForDb)
 {
     var eventDb = _context.Events.Single(s => s.EventId == eventForDb.EventId);
     string tr = _context.Database.SqlQuery<string>(string.Format("Select dbo.ChangeToTranslit('{0}')", eventForDb.Title.Replace("'", "-"))).Single();
     bool urlExist = _context.Events.Where(w => w.EventId != eventForDb.EventId).Any(a => a.TranslitUrl == tr);
     if (urlExist)
     {
         tr = string.Format("{0}_{1}", tr, eventForDb.EventId.ToString().Substring(eventForDb.EventId.ToString().Length - 4));
     }
     eventForDb.TranslitUrl = tr;
     eventForDb.DateCreate = eventDb.DateCreate;
     eventForDb.PicturePath = eventDb.PicturePath;
     eventForDb.PictureFileName = eventDb.PictureFileName;
     eventForDb.PictureFileNameSmall = eventDb.PictureFileNameSmall;
     _context.Entry(eventDb).CurrentValues.SetValues(eventForDb);
     _context.SaveChanges();
     return true;
 }