Пример #1
0
 public JsonResult CreateNewGuide(string title, string comment, int eventId, int bossId)
 {
     try
     {
         var    file       = Request.Form.Files["image"];
         var    folderPath = Path.Combine("uploads", "img");
         var    pathToSave = Path.Combine(_env.WebRootPath, folderPath);
         string dbPath     = null;
         if (file != null && file.Length > 0)
         {
             var ext = Path.GetExtension(file.FileName);
             if (ext != ".jpg" && ext != ".png" && ext != ".gif" && ext != ".jpeg")
             {
                 return(Json(new
                 {
                     message = "Error: 图像格式无法识别"
                 }));
             }
             var fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"');
             //var fullPath = Path.Combine(pathToSave, fileName);
             string renameFile = Convert.ToString(Guid.NewGuid()) + "." + fileName.Split('.').Last();
             var    fullPath   = Path.Combine(pathToSave, renameFile);
             dbPath = Path.Combine(folderPath, renameFile);
             using (var stream = new FileStream(fullPath, FileMode.Create))
             {
                 file.CopyTo(stream);
             }
         }
         var context  = new DatabaseModels.Saren_BotContext();
         var newGuide = new DatabaseModels.Guides();
         if (bossId == 0)
         {
             newGuide.EventId = null;
             newGuide.BossId  = null;
         }
         else
         {
             newGuide.EventId = eventId;
             newGuide.BossId  = bossId;
         }
         newGuide.Title    = title;
         newGuide.Comment  = comment;
         newGuide.ImageUrl = dbPath;
         context.Guides.Add(newGuide);
         context.SaveChanges();
     }
     catch (Exception ex)
     {
         return(Json(new
         {
             message = "Error: " + ex.Message
         }));
     }
     return(Json(new
     {
         message = "Success"
     }));
 }
Пример #2
0
        public JsonResult RemoveGuides(int guideId)
        {
            var context = new DatabaseModels.Saren_BotContext();

            try
            {
                var guide = context.Guides.Where(g => g.GuideId == guideId).FirstOrDefault().Status = "Inactive";
                context.SaveChanges();
            }
            catch (Exception ex)
            {
                return(Json(new
                {
                    message = "Error: " + ex.Message
                }));
            }
            return(Json(new
            {
                message = "Success"
            }));
        }
Пример #3
0
        public JsonResult EditRecord(int battleId, string nickname, string bossName, int?damage)
        {
            var context = new DatabaseModels.Saren_BotContext();

            try
            {
                var battle = context.Battles.Where(b => b.BattleId == battleId).FirstOrDefault();
                battle.MemberId = context.Member.Where(m => m.Nickname == nickname).FirstOrDefault().MemberId;
                battle.BossId   = context.Boss.Where(b => b.BossName == bossName).FirstOrDefault().BossId;
                battle.Damage   = damage;
                context.SaveChanges();
            }
            catch (Exception e)
            {
                return(Json(new
                {
                    message = "Error: " + e.Message
                }));
            }
            return(Json(new
            {
                message = "Success"
            }));
        }