示例#1
0
 public ActionResult Create(ResponseMusic ResponseMusic)
 {
     if (ModelState.IsValid)
     {
         ResponseMusicRepository.Add(ResponseMusic);
         ResponseMusicRepository.Context.Commit();
         return RedirectToAction("Index");
     }
     return View(ResponseMusic);
 }
示例#2
0
        public ActionResult Edit(ResponseMusic ResponseMusic)
        {
            if (ModelState.IsValid)
            {
                ResponseMusicRepository.Update(ResponseMusic);
                ResponseMusicRepository.Context.Commit();

                return Redirect("/ResponseMusic/Index");
            }
            return View(ResponseMusic);
        }
示例#3
0
        public ActionResult UpLoadMusic()
        {
            HttpPostedFileBase File = Request.Files[0];
            if (File != null)
            {
                if (User.Identity.Name != "")
                {
                    //获得上传的名字
                    string strPath = File.FileName;
                    string type = strPath.Substring(strPath.LastIndexOf(".") + 1).ToLower();
                    if (ValidateMusic(type))
                    {
                        //获取上传用户id
                        int userid = WebSecurity.GetUserId(User.Identity.Name);

                        ResponseMusic ResponseMusic = new ResponseMusic();
                        ResponseMusic.AddTime = DateTime.Now;
                        ResponseMusic.UserId = userid;
                        ResponseMusic.MusicName = File.FileName.Replace("." + type, "");
                        string uppath = System.Web.HttpContext.Current.Server.MapPath("~/images/ResponseMusic/" + userid.ToString());
                        ResponseMusic.MusicUrl = "/images/ResponseMusic/" + userid.ToString() + "/" + File.FileName;
                        if (!Directory.Exists(uppath))
                        {
                            Directory.CreateDirectory(uppath);
                        }

                        if (File.ContentLength < 1024 * 1024 * 5)
                        {
                            if (ResponseMusicRepository.Find(Specification<ResponseMusic>.Eval(o => o.MusicName == strPath.Replace("." + type, "") && o.UserId == userid)) == null)
                            {
                                File.SaveAs(uppath + "\\" + File.FileName);
                                if (ModelState.IsValid)
                                {
                                    ResponseMusicRepository.Add(ResponseMusic);
                                    ResponseMusicRepository.Context.Commit();
                                    return Redirect("/ResponseMusic/Index");
                                }
                            }
                            else
                            {
                                TempData["ErrorMessage"] = "语音名称已经存在";
                            }
                        }
                        else
                        {
                            TempData["ErrorMessage"] = "语音大小小于5M";
                        }
                    }
                    else
                    {
                        TempData["ErrorMessage"] = "格式不对";
                    }
                }
                else
                {
                }
            }
            else
            {
                TempData["ErrorMessage"] = "上传语音不能为空";
            }
            return Redirect("/ResponseMusic/Create");
        }