コード例 #1
0
 public ActionResult Create(Track track)
 {
     if (ModelState.IsValid) {
         trackRepository.InsertOrUpdate(track);
         trackRepository.Save();
         return RedirectToAction("Index");
     } else {
         return View();
     }
 }
コード例 #2
0
        public ActionResult Upload(UploadTrack trackInfo)
        {
            Track track = new Track();
            track.TrackName = trackInfo.TrackName;
            track.Author = trackInfo.Author;
            track.UserName = WebSecurity.CurrentUserName;
            track.FileName = fileName;
            track.Like = 0;
            track.Listenings = 0;
            track.Description = new Markdown().Transform(trackInfo.Description);
            TrackRepository trackRepository = new TrackRepository();
            trackRepository.InsertOrUpdate(track);
            var tagList = trackInfo.Tags.Split(',');
            TagRepository tagRepository = new TagRepository();
            TagsInTracks tagsInTracks;
            Tag tag;
            TagsInTracksRepository tagInTrackRepository = new TagsInTracksRepository();
            foreach(var tagName in tagList)
            {
                tagsInTracks = new TagsInTracks();
                tagsInTracks.Track = track;
                if (tagRepository.TagExist(tagName))
                {
                    tagsInTracks.TagId = tagRepository.TagSearchId(tagName);
                }
                else
                {
                    tag = new Tag();
                    tag.TagName = tagName;
                    tagRepository.InsertOrUpdate(tag);
                    tagsInTracks.Tag = tag;
                }
                tagInTrackRepository.InsertOrUpdate(tagsInTracks);
                tagInTrackRepository.Save();

            }
            TrackData trackIndex = new TrackData();
            trackIndex.Author = trackInfo.Author;
            trackIndex.Id = track.TrackId;
            trackIndex.Tags = trackInfo.Tags;
            trackIndex.TrackName = trackInfo.TrackName;
            trackIndex.TrackPath = fileName;
            AddToIndex(trackIndex);

            return RedirectToAction("Index", "Home");
        }
コード例 #3
0
 private void SaveRepository(Statistic statistic, Like like, Track track)
 {
     trackRepository.InsertOrUpdate(track);
     trackRepository.Save();
     likeRepository.Save();
     _statisticRepository.InsertOrUpdate(statistic);
     _statisticRepository.Save();
 }
コード例 #4
0
 public void InsertOrUpdate(Track track)
 {
     if (track.TrackId == default(int)) {
         // New entity
         context.Tracks.Add(track);
     } else {
         // Existing entity
         context.Entry(track).State = EntityState.Modified;
     }
 }