Ejemplo n.º 1
0
        public ActionResult EditGame(SubjectInfoModel model)
        {
            if (model != null && ModelState.IsValid)
            {
                var file1 = Request.Files["Picture"];
                var file2 = Request.Files["ResultPicture"];
                if (model.PictureId == 0 && (file1 == null || !IsImage(file1.ContentType)))
                {
                    model.PictureUrl = "";
                    ModelState.AddModelError("", "please choose a picture");
                }
                if (model.ResultPictureId == 0 && (file2 == null || !IsImage(file2.ContentType)))
                {
                    model.ResultPictureUrl = "";
                    ModelState.AddModelError("", "please choose a result picture");
                }
                if (!ModelState.IsValid)
                {
                    return View(model);
                }

                var subject = _subjectinfoInfoService.GetSubjectById(model.Id);
                if (subject != null)
                {
                    Picture picture = null;
                    Picture resultPicture = null;

                    if (model.PictureId == 0)
                    {
                        string filename = DateTime.Now.ToString("yyyyMMddHHmmssfff") +
                            System.IO.Path.GetExtension(file1.FileName);
                        string path = Path + filename;
                        file1.SaveAs(Server.MapPath(path));
                        picture = subject.Picture;
                        subject.Picture = new Picture()
                        {
                            Id = 0,
                            FileName = filename,
                            FileType = file1.ContentType,
                            Url = path
                        };
                    }

                    if (model.ResultPictureId == 0)
                    {
                        string filename = DateTime.Now.ToString("yyyyMMddHHmmssfff") +
                            System.IO.Path.GetExtension(file2.FileName);
                        string path = Path + filename;
                        file2.SaveAs(Server.MapPath(path));
                        resultPicture = subject.ResultPicture;
                        subject.ResultPicture = new Picture()
                        {
                            Id = 0,
                            FileName = filename,
                            FileType = file2.ContentType,
                            Url = path
                        };
                    }

                    subject.Title = model.Title;
                    subject.Description = model.Description;
                    subject.ResultTitle = model.ResultTitle;
                    subject.AdditionNum = model.AdditionNum;
                    subject.Order = model.Order;

                    _subjectinfoInfoService.Update(subject);

                    //delete old picture
                    if (picture != null)
                    {
                        _pictureService.DeletePicture(picture);
                        string path = Server.MapPath(picture.Url);
                        if (System.IO.File.Exists(path))
                        {
                            System.IO.File.Delete(path);
                        }
                    }
                    if (resultPicture != null)
                    {
                        _pictureService.DeletePicture(resultPicture);
                        string path = Server.MapPath(resultPicture.Url);
                        if (System.IO.File.Exists(path))
                        {
                            System.IO.File.Delete(path);
                        }
                    }

                    return RedirectToAction("EditGame", new { subjectId = subject.Id });
                }
            }

            return View(model);
        }
Ejemplo n.º 2
0
        public ActionResult EditGame(int subjectId)
        {
            var data = new SubjectInfoModel();

            var subject = _subjectinfoInfoService.GetSubjectById(subjectId);
            if (subject != null)
            {
                data = subject.ToAdminModel();
                data.Options = subject.Options.Where(o => o.IsValid).Select(o => o.ToAdminModel())
                    .OrderBy(o => o.ResultType).ThenByDescending(o => o.Order).ToList();
            }

            return View(data);
        }
Ejemplo n.º 3
0
        public ActionResult NewGame()
        {
            ViewBag.Create = true;
            var model = new SubjectInfoModel();

            return View("EditGame", model);
        }
Ejemplo n.º 4
0
        public ActionResult NewGame(SubjectInfoModel model)
        {
            if (model != null && ModelState.IsValid)
            {
                var file1 = Request.Files["Picture"];
                var file2 = Request.Files["ResultPicture"];
                if (file1 == null || !IsImage(file1.ContentType) || file2 == null || !IsImage(file2.ContentType))
                {
                    ModelState.AddModelError("", "please choose a picture");
                }
                else
                {
                    var subject = model.ToEntity();
                    string filename = DateTime.Now.ToString("yyyyMMddHHmmssfff") +
                        System.IO.Path.GetExtension(file1.FileName);
                    string path = Path + filename;
                    file1.SaveAs(Server.MapPath(path));
                    subject.Picture = new Picture()
                    {
                        Id = 0,
                        FileName = filename,
                        FileType = file1.ContentType,
                        Url = path
                    };
                    filename = DateTime.Now.ToString("yyyyMMddHHmmssfff") +
                        System.IO.Path.GetExtension(file2.FileName);
                    path = Path + filename;
                    file2.SaveAs(Server.MapPath(path));
                    subject.ResultPicture = new Picture()
                    {
                        Id = 0,
                        FileName = filename,
                        FileType = file2.ContentType,
                        Url = path
                    };

                    _subjectinfoInfoService.Create(subject);
                    return RedirectToAction("EditGame", new { subjectId = subject.Id });
                }
            }

            ViewBag.Create = true;
            return View("EditGame", model);
        }
Ejemplo n.º 5
0
        public ActionResult Hide([DataSourceRequest]DataSourceRequest request, SubjectInfoModel model)
        {
            if (model != null && ModelState.IsValid)
            {
                _subjectinfoInfoService.Hide(model.Id);
            }

            return GridGet(request);
        }