public IActionResult UpdateBasic(UpdateBasicSingerViewModel model)
        {
            var singer = new SingerModel()
            {
                Id          = model.Id,
                ForeignName = model.ForeignName,
                Nationality = model.Nationality,
                MenderId    = HttpContext.Session.GetCurrentUserId(),
            };

            singer = _singerAppService.UpdateBasic(singer);
            return(Json(new JsonResultEntity()
            {
                Message = "更新基本信息成功!",
                JsonObject = Json(new SingerViewModel()
                {
                    Id = singer.Id,
                    MenderId = singer.MenderId,
                    MenderName = singer.MenderName,
                    ForeignName = singer.ForeignName,
                    Nationality = singer.Nationality,
                    LastModificationTime = singer.LastModificationTime?.ToStandardDateOfChina()
                })
            }));
        }
Beispiel #2
0
        public async Task <IActionResult> EditSinger(int id)
        {
            var Singer = await _context.Singer.FindAsync(id);

            ViewData["ListCountry"] = new SelectList(SingerModel.GetCountry());
            return(View(Singer));
        }
        public override bool InsertSinger(SingerModel singer)
        {
            bool existSinger           = false;
            bool inserted              = !existSinger;
            List <SingerModel> singers = GetSingers();

            try
            {
                existSinger = singers.Any(x => x.Name == singer.Name);
                if (!existSinger)
                {
                    using (SqlConnection connection = Conection.GetConection())
                    {
                        string     query      = "insert into singersTable values (@name, @kindOfMusic, @songs)";
                        SqlCommand sqlCommand = new SqlCommand(query, connection);
                        sqlCommand.Parameters.AddWithValue("@name", singer.Name);
                        sqlCommand.Parameters.AddWithValue("@kindOfMusic", singer.KindOfMusic);
                        sqlCommand.Parameters.AddWithValue("@songs", string.Join(",", singer.Songs));
                        connection.Open();
                        sqlCommand.ExecuteNonQuery();
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(inserted);
        }
        public IActionResult Create(CreateSingerViewModel model)
        {
            var singer = new SingerModel()
            {
                Name        = model.Name.Trim(),
                ForeignName = model.ForeignName,
                Nationality = model.Nationality,
                CreatorId   = HttpContext.Session.GetCurrentUserId()
            };

            singer = _singerAppService.Create(singer);
            return(Json(new JsonResultEntity()
            {
                Message = "添加歌唱家成功!",
                JsonObject = Json(new SingerViewModel()
                {
                    Id = singer.Id,
                    CreatorId = singer.CreatorId,
                    Name = singer.Name,
                    CreatorName = singer.CreatorName,
                    ForeignName = singer.ForeignName,
                    Nationality = singer.Nationality,
                    CreationTime = singer.CreationTime.ToStandardDateOfChina(),
                })
            }));
        }
Beispiel #5
0
 public static SingerViewModel ModelToViewModel(SingerModel model)
 {
     return(new SingerViewModel()
     {
         Name = model.Name, KindOfMusic = model.KindOfMusic, Songs = model.Songs
     });
 }
        public Singer Bind(SingerModel singerModel)
        {
            Singer singer = new Singer();

            singer.Id   = singerModel.Id;
            singer.Name = singerModel.Name;

            return(singer);
        }
        public static string GetFullFileNameOfMusic(string contentDisposition, SingerModel singer, AlbumModel album)
        {
            var fileName = ContentDispositionHeaderValue
                           .Parse(contentDisposition)
                           .FileName
                           .Trim('"');

            return(Path.Combine(GlobalConstants.MusicsRootPath, GlobalConstants.MusicsRootDirectoryName,
                                $"{singer.Id.ToString()}-{singer.Name}", album.Name, $"{DateTime.Now.ToString("yyyyMMddHHmmss")}-{fileName}"));
        }
Beispiel #8
0
        public ActionResult Edit(string id)
        {
            var         Singer = SingerService.GetById(id);
            SingerModel gm     = new SingerModel()
            {
                Id = Singer.Id, Name = Singer.Name
            };

            return(View(gm));
        }
 public ActionResult Edit([Bind(Include = "Id,Name")] SingerModel singerModel)
 {
     if (ModelState.IsValid)
     {
         SingerBinder singerBinder = new SingerBinder();
         Singer       singer       = new Singer();
         singer = singerBinder.Bind(singerModel);
         db.Entry(singer).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(singerModel));
 }
        public ActionResult Create([Bind(Include = "Id,Name")] SingerModel singerModel)
        {
            if (ModelState.IsValid)
            {
                SingerBinder singerBinder = new SingerBinder();
                Singer       singer       = singerBinder.Bind(singerModel);
                db.Singer.Add(singer);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(singerModel));
        }
Beispiel #11
0
        /// <summary>
        /// 更新基本信息
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public Singer UpdateBasic(SingerModel model)
        {
            _userManager.ValidAdminByUserId((int)model.MenderId);
            ValidForUpdateBasic(model, out Singer singer);

            singer.MenderId             = model.MenderId;
            singer.ForeignName          = model.ForeignName;
            singer.Nationality          = model.Nationality;
            singer.LastModificationTime = DateTime.Now;

            Save();
            return(singer);
        }
        public ICollection <SingerModel> Bind(ICollection <Singer> singerList)
        {
            ICollection <SingerModel> singerModelList = new List <SingerModel>();

            foreach (Singer item in singerList)
            {
                SingerModel singerModel = new SingerModel();
                singerModel.Id   = item.Id;
                singerModel.Name = item.Name;
                singerModelList.Add(singerModel);
            }

            return(singerModelList);
        }
Beispiel #13
0
 public async Task <IActionResult> Edit(int id, [Bind("Id,Image,Name,BirthDay,Description,Country")] SingerModel singerModel, IFormFile ful)
 {
     if (id != singerModel.Id)
     {
         return(NotFound());
     }
     if (ModelState.IsValid)
     {
         try
         {
             singerModel.NameUnsigned = RemoveUnicode(singerModel.Name);
             if (ful != null)
             {
                 string t    = singerModel.Id + "." + ful.FileName.Split(".")[ful.FileName.Split(".").Length - 1];
                 var    path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/img/singer", singerModel.Image);
                 if (System.IO.File.Exists(path))
                 {
                     System.IO.File.Delete(path);
                 }
                 path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/img/singer", t);
                 using (var stream = new FileStream(path, FileMode.Create))
                 {
                     await ful.CopyToAsync(stream);
                 }
                 singerModel.Image = t;
                 _context.Update(singerModel);
                 await _context.SaveChangesAsync();
             }
             else
             {
                 _context.Update(singerModel);
                 await _context.SaveChangesAsync();
             }
         }
         catch (DbUpdateConcurrencyException)
         {
             if (!SingerExists(singerModel.Id))
             {
                 return(NotFound());
             }
             else
             {
                 throw;
             }
         }
         return(RedirectToAction(nameof(Index)));
     }
     return(View(singerModel));
 }
Beispiel #14
0
 private void ValidForUpdateBasic(SingerModel model, out Singer singer)
 {
     ValidForDelete(model.Id, out singer);
     if (model.ForeignName?.Length > 32)
     {
         ThrowException("外文名不能超过32个字符");
     }
     if (string.IsNullOrWhiteSpace(model.Nationality))
     {
         ThrowException("国籍不能为空");
     }
     if (model.Nationality.Length > 32)
     {
         ThrowException("国籍不能超过32个字符");
     }
 }
        public SingerModel UpdateBasic(SingerModel model)
        {
            var singer = _singerManager.UpdateBasic(model);

            return(new SingerModel()
            {
                Id = singer.Id,
                MenderId = singer.Mender.Id,
                Name = singer.Name,
                MenderName = singer.Mender.UserName,
                ForeignName = singer.ForeignName,
                Nationality = singer.Nationality,
                CreationTime = singer.CreationTime,
                LastModificationTime = singer.LastModificationTime
            });
        }
        public SingerModel Create(SingerModel model)
        {
            var singer = _singerManager.Create(model);

            return(new SingerModel()
            {
                Id = singer.Id,
                CreatorId = singer.CreatorId,
                CreatorName = singer.Creator.NickName,
                Name = singer.Name,
                ForeignName = singer.ForeignName,
                Nationality = singer.Nationality,
                CreationTime = singer.CreationTime,
            }
                   );
        }
Beispiel #17
0
        public Singer Create(SingerModel model)
        {
            _userManager.ValidAdminByUserId(model.CreatorId);
            ValidForCreate(model);

            var singer = new Singer()
            {
                CreatorId    = model.CreatorId,
                Name         = model.Name,
                ForeignName  = model.ForeignName,
                Nationality  = model.Nationality,
                CreationTime = DateTime.Now,
                IsPublished  = false,
            };

            return(Create(singer));
        }
Beispiel #18
0
        public async Task <ActionResult> Edit(SingerModel Singer)
        {
            if (ModelState.IsValid)
            {
                OperationDetails operationDetails = await SingerService.Update(new SingerDTO()
                {
                    Id = Singer.Id, Name = Singer.Name
                });

                if (operationDetails.Succedeed)
                {
                    return(RedirectToAction("SingerView"));
                }
                else
                {
                    ModelState.AddModelError(operationDetails.Property, operationDetails.Message);
                }
            }
            return(View(Singer));
        }
Beispiel #19
0
        public async Task <IActionResult> Create([Bind("Image,Name,BirthDay,Description,Country")] SingerModel singerModel, IFormFile ful)
        {
            if (ModelState.IsValid)
            {
                singerModel.NameUnsigned = RemoveUnicode(singerModel.Name);
                _context.Add(singerModel);
                await _context.SaveChangesAsync();

                var path = Path.Combine(
                    Directory.GetCurrentDirectory(), "wwwroot/img/singer", singerModel.Id + "." + ful.FileName.Split(".")[ful.FileName.Split(".").Length - 1]);
                using (var stream = new FileStream(path, FileMode.Create))
                {
                    await ful.CopyToAsync(stream);
                }
                singerModel.Image = singerModel.Id + "." + ful.FileName.Split(".")[ful.FileName.Split(".").Length - 1];
                _context.Update(singerModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(singerModel));
        }
Beispiel #20
0
 private void ValidForCreate(SingerModel model)
 {
     if (string.IsNullOrWhiteSpace(model.Name))
     {
         ThrowException("姓名不能为空!");
     }
     if (model.Name.Length > 32)
     {
         ThrowException("姓名不能超过32个字符!");
     }
     // ? 操作符  如果为null则返回false
     if (model.ForeignName?.Length > 32)
     {
         ThrowException("外文名不能超过32个字符");
     }
     if (string.IsNullOrWhiteSpace(model.Nationality))
     {
         ThrowException("国籍不能为空");
     }
     if (model.Nationality.Length > 32)
     {
         ThrowException("国籍不能超过32个字符");
     }
 }
 public abstract bool InsertSinger(SingerModel singer);
Beispiel #22
0
 public IActionResult CreateSinger()
 {
     ViewData["ListCountry"] = new SelectList(SingerModel.GetCountry());
     return(View());
 }