Пример #1
0
        public ActionResult CreateSketch(EditSketchViewModel viewModel, bool returnToProject, bool startNewSketch, bool duplicateSketch)
        {
            if (viewModel != null && viewModel.ProjectId != null && viewModel.DimensionId != null && ModelState.IsValid)
            {
                // Since an action is being executed after the session expires (and going to the Index page after that),
                // this check is necessary to prevent a NullReferenceException
                if (System.Web.HttpContext.Current.Session["userId"] != null)
                {
                    viewModel.UserId = (int)System.Web.HttpContext.Current.Session["userId"];

                    bool hasMultipleRequests = ViewData.ContainsKey("MultipleRequests");
                    int  sketchId            = -1;

                    if (!hasMultipleRequests)
                    {
                        sketchId = Repository.Create(viewModel.ToDomainModel());

                        GlobalHost.ConnectionManager.GetHubContext <MorphologicalChartHub>().Clients.All.refresh();
                    }

                    if (sketchId > 0 || hasMultipleRequests)
                    {
                        if (returnToProject)
                        {
                            return(RedirectToAction("EditProject", "Project", new { ProjectId = viewModel.ProjectId.Value }));
                        }
                        else if (startNewSketch)
                        {
                            return(RedirectToAction("EditSketch",
                                                    new { ProjectId = viewModel.ProjectId, DimensionId = viewModel.DimensionId }));
                        }
                        else if (duplicateSketch)
                        {
                            return(EditSketch(viewModel.ProjectId, viewModel.DimensionId, null));
                        }
                        else
                        {
                            return(EditSketch(viewModel.ProjectId, viewModel.DimensionId, viewModel.SketchId));
                        }
                    }
                }
                else
                {
                    return(RedirectToAction("Index", "Security"));
                }
            }

            return(View("Error"));
        }
Пример #2
0
        public ActionResult UpdateSketch(EditSketchViewModel viewModel, bool returnToProject, bool startNewSketch, bool duplicateSketch)
        {
            if (viewModel != null && viewModel.ProjectId != null && viewModel.SketchId != null && ModelState.IsValid)
            {
                if (!ViewData.ContainsKey("MultipleRequests"))
                {
                    try
                    {
                        Repository.Update(viewModel.ToDomainModel());
                    }
                    catch (EntityAlreadyDeletedException ex)
                    {
                        ModelState.AddModelError("Title", ex.Message);

                        return(RedirectToAction("EditSketch", new { viewModel.ProjectId, viewModel.DimensionId, viewModel.SketchId }));
                    }

                    GlobalHost.ConnectionManager.GetHubContext <MorphologicalChartHub>().Clients.All.refresh();
                }

                if (returnToProject)
                {
                    return(RedirectToAction("EditProject", "Project", new { ProjectId = viewModel.ProjectId.Value }));
                }
                if (startNewSketch)
                {
                    return(RedirectToAction("EditSketch",
                                            new { ProjectId = viewModel.ProjectId, DimensionId = viewModel.DimensionId }));
                }
                if (duplicateSketch)
                {
                    return(EditSketch(viewModel.ProjectId, viewModel.DimensionId, null));
                }
                return(EditSketch(viewModel.ProjectId, viewModel.DimensionId, viewModel.SketchId));
            }

            return(View("Error"));
        }