Пример #1
0
        public IHttpActionResult Create(CreateSongModel model)
        {
            IHttpActionResult httpActionResult;

            if (string.IsNullOrEmpty(model.Name))
            {
                error.Add("Name is required");
            }
            if (error.errors.Count == 0)
            {
                Songs Songs = new Songs();
                Songs.UserId      = model.UserId;
                Songs.Name        = StandardString.StandardSongName(model.Name);
                Songs.KeyIds      = model.KeyIds;
                Songs.CreatedDate = model.CreatedDate;
                Songs             = db.Songs.Add(Songs);
                db.SaveChanges();
                httpActionResult = Ok(new SongsModel(Songs));
            }
            else
            {
                httpActionResult = new ErrorActionResult(Request, HttpStatusCode.BadRequest, error);
            }
            return(httpActionResult);
        }
Пример #2
0
        public async Task <IActionResult> CreateSong(CreateSongModel model)
        {
            if (ModelState.IsValid)
            {
                SongData songData = new SongData();

                using (var memoryStream = new MemoryStream())
                {
                    await model.SongData.CopyToAsync(memoryStream);

                    songData.Data = memoryStream.ToArray();
                }

                bool result = await repository.CreateSongDataAsync(songData);

                if (result)
                {
                    Song song = new Song
                    {
                        SongName   = model.SongName,
                        TrackNum   = model.TrackNum,
                        AlbumId    = model.AlbumId,
                        SongDataId = songData.SongDataId,
                        VideoLink  = model.VideoLink
                    };
                    result = await repository.CreateSongAsync(song);

                    if (result)
                    {
                        return(RedirectToAction("CreateSong", "Create"));
                    }
                    else
                    {
                        ModelState.AddModelError("", "An error occured while creating the Song");
                    }
                }
                else
                {
                    ModelState.AddModelError("", "An error occured while creating the Song");
                }
            }
            return(View(model));
        }