示例#1
0
        public async Task <ActionResult> Create(MusicChangeModel music)
        {
            if (ModelState.IsValid)
            {
                var fileName = Path.GetFileName(music.File.FileName);
                var path     = Path.Combine("/uploads/", fileName);
                OperationDetails operationDetails = await MusicService.Create(new MusicDTO()
                {
                    Name     = music.Name,
                    Path     = path,
                    GenreId  = music.GenreId,
                    SingerId = music.SingerId,
                    UserId   = User.Identity.GetUserId()
                });

                music.File.SaveAs(Server.MapPath(path));
                if (operationDetails.Succedeed)
                {
                    return(RedirectToAction("MusicView"));
                }
                else
                {
                    ModelState.AddModelError(operationDetails.Property, operationDetails.Message);
                }
            }
            return(View(music));
        }
示例#2
0
        public ActionResult Edit(string id)
        {
            var music = MusicService.GetById(id);

            MusicChangeModel.GetSingerSelectItems =
                SingerService.GetAll().Select(m => new SelectListItem()
            {
                Text = m.Name, Value = m.Id
            });
            MusicChangeModel.GetGenreSelectItems =
                GenreService.GetAll().Select(m => new SelectListItem()
            {
                Text = m.Name, Value = m.Id
            });
            MusicChangeModel gm = new MusicChangeModel()
            {
                Id       = music.Id,
                Name     = music.Name,
                SingerId = music.SingerId,
                GenreId  = music.GenreId
            };

            return(View(gm));
        }