コード例 #1
0
ファイル: Player.cs プロジェクト: TeamHTTP418/FinalProject
 public bool addTaskPoints(Task task)
 {
     bool result = false;
     if (isFrozen())
     {
         result =  addHeldPoints(task.type, task.value);
         if (result && task.isMilestone && task.numberCompleted < task.maxCompletedBonus)
         {
             lock (mileLock)
             {
                 if (task.numberCompleted < task.maxCompletedBonus)
                 {
                     result = addHeldPoints(task.type, task.bonusPoints.Value);
                     task.numberCompleted++;
                 }
             }
         }
     }
     else
     {
         result = addPoints(task.type, task.value);
         if (result && task.isMilestone && task.numberCompleted < task.maxCompletedBonus)
         {
             lock (mileLock)
             {
                 if (task.numberCompleted < task.maxCompletedBonus)
                 {
                     result = addPoints(task.type, task.bonusPoints.Value);
                     task.numberCompleted++;
                 }
             }
         }
     }
     return result;
 }
コード例 #2
0
        public ActionResult Create(Task task, HttpPostedFileBase icon)
        {
            if (task.isMilestone == false)
            {
                task.maxCompletedBonus = null;
                task.numberCompleted = null;
                task.iconName = null;
                task.bonusPoints = null;
            }
            if (ModelState.IsValid)
            {
                if (icon != null && icon.ContentLength > 0 && icon.ContentType.StartsWith("image/") && task.isMilestone)
                {
                    string iconName = Path.GetFileName(icon.FileName);
                    string path = Path.Combine(Server.MapPath("~/Content/icons"), iconName);
                    icon.SaveAs(path);
                    task.iconName = iconName;
                }
                task.token = Guid.NewGuid().ToString();
                db.Tasks.Add(task);
                db.SaveChanges();
                return RedirectToAction("Details", new { id = task.ID });
            }

            //Something was wrong, reshow the create view
            var scoreTypeSelect = from TaskType e in Enum.GetValues(typeof(TaskType))
                                  select new { Id = e, Name = e.ToString() };
            ViewBag.typeSelect = new SelectList(scoreTypeSelect, "Id", "Name", null);

            DirectoryInfo iconDirectory = new DirectoryInfo(Server.MapPath(@"../Content/icons"));
            var icons = from FileInfo f in iconDirectory.GetFiles()
                        select new { Id = Path.GetFileName(f.Name) };
            ViewBag.iconSelect = new SelectList(icons, "Id", "Id");
            return View();
        }
コード例 #3
0
 public ActionResult Delete(Task task, bool removeIcon = false)
 {
     if (removeIcon)
     {
         DirectoryInfo iconDirectory = new DirectoryInfo(Server.MapPath(@"../Content/icons"));
         FileInfo icon = iconDirectory.EnumerateFiles().Where(s => s.Name == task.iconName).FirstOrDefault();
         if (icon != null)
         {
             icon.Delete();
         }
     }
     db.Tasks.Remove(task);
     db.SaveChanges();
     return RedirectToAction("Index");
 }
コード例 #4
0
        public ActionResult Edit(Task task, HttpPostedFileBase icon)
        {
            if (task.isMilestone == false)
            {
                task.maxCompletedBonus = null;
                task.numberCompleted = null;
                task.iconName = null;
                task.bonusPoints = null;
            }
            if (icon != null && icon.ContentLength > 0 && icon.ContentType.StartsWith("image/") && task.isMilestone)
            {
                string iconName = Path.GetFileName(icon.FileName);
                string path = Path.Combine(Server.MapPath("~/Content/icons"), iconName);
                icon.SaveAs(path);
                task.iconName = iconName;
            }
            if (ModelState.IsValid)
            {
                db.Entry(task).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            var scoreTypeSelect = from TaskType e in Enum.GetValues(typeof(TaskType))
                                  select new { Id = e, Name = e.ToString() };
            ViewBag.typeSelect = new SelectList(scoreTypeSelect, "Id", "Name", task.type.ToString());

            DirectoryInfo iconDirectory = new DirectoryInfo(Server.MapPath(@"~/Content/icons"));
            var icons = from FileInfo f in iconDirectory.GetFiles()
                        select new { Id = Path.GetFileName(f.Name) };
            ViewBag.iconSelect = new SelectList(icons, "Id", "Id");
            return View(task);
        }
コード例 #5
0
 public static PlayerToTask GetPTT(Player player, Task task)
 {
     return new PlayerToTask { player = player, task = task, when = DateTime.Now };
 }