/// <summary> /// 删除奖项 /// </summary> /// <param name="id"></param> /// <returns></returns> public JsonResult DeletePrize(int id) { var error = string.Empty; using (var _db = new LuckyDrawEntities()) { var prize = _db.Prizes.Find(id); if (prize != null) { prize.State = false; var result = _db.SaveChanges(); if (result > 0) { return(Json(new { success = true })); } error = "删除失败"; } else { error = "找不到该奖项"; } } return(Json(new { success = false, msg = error })); }
public async Task <JsonResult> UploadHeadImg() { var file = Request.Files["HeadImg"]; if (file != null && file.ContentLength > 0) { var extend = Path.GetExtension(file.FileName); var path = await FileHelper.Upload(file, Guid.NewGuid().ToString("N") + extend); var headImg = _db.Manus.SingleOrDefault(x => x.Key.Equals("HeadImg")); headImg.Value = path; _db.SaveChanges(); return(Json(new { success = true, result = path })); } return(Json(new { success = false, msg = "上传图片失败" })); }
public string InsertSmallSet(string name, int num, string color) { using (LuckyDrawEntities entitys = new LuckyDrawEntities()) { try { SmallSet ss = new SmallSet(); ss.name = name; ss.num = num; ss.color = color; entitys.SmallSets.Add(ss); entitys.SaveChanges(); } catch (Exception) { return(JsonHelper.GetJson("false")); } return(JsonHelper.GetJson("true")); } }
public string SubtractSmall(int id) { using (LuckyDrawEntities entitys = new LuckyDrawEntities()) { try { List <Models.SmallSet> list = entitys.SmallSets.Where(a => a.id == id).ToList(); if (list.Count > 0) { SmallSet ss = list[0]; ss.num = ss.num - 1; entitys.SaveChanges(); } } catch (Exception) { return(JsonHelper.GetJson("false")); } return(JsonHelper.GetJson("true")); } }
/// <summary> /// Deletes the Photo set. /// </summary> /// <param name="id">The identifier.</param> /// <returns></returns> /// 创建人:李允智 /// 创建时间:2016/1/14 /// 描述:删除照片 public string DelPhotoSet(int id) { using (LuckyDrawEntities entitys = new LuckyDrawEntities()) { try { List <Models.PhotoSet> list = entitys.PhotoSets.Where(a => a.id == id).ToList(); if (list.Count > 0) { PhotoSet ss = list[0]; entitys.PhotoSets.Remove(ss); entitys.SaveChanges(); } } catch (Exception) { return(JsonHelper.GetJson("false")); } return(JsonHelper.GetJson("true")); } }
/// <summary> /// 添加或者编辑奖项 /// </summary> /// <param name="model"></param> /// <returns></returns> public ActionResult EditPrize(Prize model) { using (var _db = new LuckyDrawEntities()) { if (model.Id > 0) { var prize = _db.Prizes.Find(model.Id); if (prize == null) { return(Json(new { success = false, msg = "找不到该奖项" })); } prize.Name = model.Name; prize.Detail = model.Detail; prize.Count = model.Count; prize.Percent = model.Percent; prize.Angle = model.Angle; } else { var prize = new Prize() { Name = model.Name, Angle = model.Angle, Percent = model.Percent, Count = model.Count, Detail = model.Detail, State = true }; _db.Prizes.Add(prize); } var result = _db.SaveChanges(); if (result > 0) { return(Json(new { success = true, item = model })); } } return(Json(new { success = false, msg = "提交失败" })); }
public string InsertPhotoSet(string name, string path, int x, int y, int x2, int y2) { Bitmap bm = new Bitmap(System.Web.HttpContext.Current.Server.MapPath(path)); Bitmap bmpOut = new Bitmap((x2 - x), (y2 - y), PixelFormat.Format24bppRgb); Graphics g = Graphics.FromImage(bmpOut); g.DrawImage(bm, new Rectangle(0, 0, (x2 - x), (y2 - y)), new Rectangle(x, y, (x2 - x), (y2 - y)), GraphicsUnit.Pixel); Random rnd = new Random(); int num = rnd.Next(5000, 1000000); string newpath = "/Data/" + num.ToString() + ".jpg"; bmpOut.Save(System.Web.HttpContext.Current.Server.MapPath(newpath)); g.Dispose(); using (LuckyDrawEntities entitys = new LuckyDrawEntities()) { try { PhotoSet ss = new PhotoSet(); ss.name = name; ss.url = newpath; entitys.PhotoSets.Add(ss); entitys.SaveChanges(); } catch (Exception) { return(JsonHelper.GetJson("false")); } return(JsonHelper.GetJson("true")); } //HttpFileCollection files = System.Web.HttpContext.Current.Request.Files; //if (files.Count > 0) //{ // Random rnd = new Random(); // string path = ""; // HttpPostedFile file = files[0]; // if (file.ContentLength > 0) // { // string fileName = file.FileName; // string extension = Path.GetExtension(fileName); // int num = rnd.Next(5000, 1000000); // path = "/Data/" + num.ToString() + extension; // file.SaveAs(System.Web.HttpContext.Current.Server.MapPath(path)); // } // using (LuckyDrawEntities entitys = new LuckyDrawEntities()) // { // try // { // PhotoSet ss = new PhotoSet(); // ss.name = name; // ss.url = path; // entitys.PhotoSets.Add(ss); // entitys.SaveChanges(); // } // catch (Exception) // { // return JsonHelper.GetJson("false"); // } // return JsonHelper.GetJson("true"); // } //} //else //{ // return JsonHelper.GetJson("false"); //} }