Esempio n. 1
0
        public void DeleteProblem(Problem Problem)
        {
            context.Entry(Problem).State = EntityState.Deleted;

            context.SaveChanges();

            return;
        }
Esempio n. 2
0
        public ActionResult Create(viewModels.NewProblemViewModel Model)
        {
            if (ModelState.IsValid)
            {
                int problemID = -1;

                // Attempt to create new problem
                try
                {
                    Problem problem = new Problem
                    {
                        Name = Model.Name,
                        TimeLimit = Model.TimeLimit,
                        MemoryLimit = Model.MemoryLimit,
                        LastModifiedTime = DateTime.Now.Truncate(TimeSpan.FromSeconds(1)), // Truncate need for comparing dates
                        Type = (ProblemTypes)Model.ProblemTypesListID,
                        Tags = new List<ProblemTag>()
                    };

                    foreach (var tagId in Model.ProblemTagsListIDs)
                    {
                        var tag = repository.ProblemTags.FirstOrDefault(t => t.ProblemTagID == tagId);
                        if (tag != null)
                            problem.Tags.Add(tag);
                    }

                    int userID = WebSecurity.CurrentUserId;
                    if (userID != 1)
                    {
                        UserProfile user = repository.Users.FirstOrDefault(u => u.UserId == userID);
                        problem.UsersCanModify = new List<UserProfile>();
                        problem.UsersCanModify.Add(user);
                    }
                    problemID = repository.AddProblem(problem);

                    SaveProblem(Model, problemID, problem.LastModifiedTime);

                    problem.Path = LocalPath.RelativeProblemsDirectory + problemID.ToString();

                    // Update problem in repository
                    repository.AddProblem(problem);

                    TestersSingleton.Instance.SendProblem(problem.ProblemID);

                    logger.Info("User " + WebSecurity.GetUserId(User.Identity.Name) +
                        " \"" + User.Identity.Name + "\" create problem " + problemID + " \"" + Model.Name + "\"");

                    return RedirectToAction("BindTournamentsToProblem", new { problemID = problem.ProblemID });
                }
                catch (Exception ex)
                {
                    logger.Error("Error occurred on user " + WebSecurity.GetUserId(User.Identity.Name) +
                        " \"" + User.Identity.Name + "\" creating problem " + problemID + " \"" + Model.Name + "\": ", ex);

                    ModelState.AddModelError("", "Произошла ошибка при создании задачи");

                    repository.DeleteProblem(problemID);
                    if (Directory.Exists(LocalPath.AbsoluteProblemsDirectory + problemID.ToString()))
                    {
                        Directory.Delete(LocalPath.AbsoluteProblemsDirectory + problemID.ToString(), true);
                    }
                }
            }

            return View(Model);
        }
Esempio n. 3
0
        public int AddProblem(Problem Problem)
        {
            if (Problem.ProblemID == 0)
            {
                Problem = context.Problems.Add(Problem);
            }
            else
            {
                context.Entry(Problem).State = EntityState.Modified;
            }
            context.SaveChanges();
            context.Entry(Problem).Reload();

            return Problem.ProblemID;
        }