Esempio n. 1
0
        public ActionResult Create(CreateProjectInput viewModel)
        {
            try
            {
                //var currentUserId = ()HttpContext.User
                if (ModelState.IsValid)
                {
                    viewModel.CreatorUserId = _currentUser.CurrentUserId;
                    viewModel.CompanyName   = _currentUser.CompanyName;
                    _projectService.Create(viewModel);

                    ModelState.Clear();

                    var newVm = new CreateProjectInput();
                    newVm.ErrorCode        = ErrorCodeHelper.Ok;
                    newVm.ErrorDescription = "¡Proyecto guardado exitosamente!";
                    return(PartialView("_createPartial", newVm));
                    //return Json(newVm, JsonRequestBehavior.AllowGet);
                }
                viewModel.ErrorCode        = ErrorCodeHelper.Error;
                viewModel.ErrorDescription = "Error al intentar guardar los datos.";
                return(PartialView("_createPartial", viewModel));
            }
            catch (Exception e)
            {
                viewModel.ErrorCode        = ErrorCodeHelper.Error;
                viewModel.ErrorDescription = e.Message;
                return(PartialView("_createPartial", viewModel));
            }
        }
Esempio n. 2
0
        public async Task CreateProject(CreateProjectInput input)
        {
            if (await _projectRepository.CountAsync(t => t.Code == input.Code) > 0)
            {
                throw new UserFriendlyException($"小区代号:【{input.Code}】已经存在!");
            }

            var project = input.MapTo <Project>();
            await _projectRepository.InsertAsync(project);
        }
        [ValidateAntiForgeryToken] //this is here to prevent XSS (cross site scripting attacks)
        public async Task <IActionResult> SaveNewProject(CreateProjectInput newProjectInput)
        {
            if (TempData.Peek("userName") == null)
            {
                return(UserNotAllowedAccess(isUserLoggedIn: false));
            }

            if (TempData.Peek("userRole").ToString() == "Employee")
            {
                return(UserNotAllowedAccess(isUserLoggedIn: true));
            }
            //if the ModelState is invalid return the user to the CreateProject page and show them the validation errors
            if (!ModelState.IsValid)
            {
                List <string> errors = ModelState.Values.SelectMany(p => p.Errors.Select(x => x.ErrorMessage)).ToList();
                TempData.Add("CreateProjectInvalid", errors);
                return(RedirectTo("ProjectManager", "CreateProject"));
            }


            var resultList = new WorkHourTrackerListResult()
            {
                Errors = new List <string>(), WorkHourTrackList = new List <dynamic>()
            };

            //the request is valid. Now, transform it into CreateProjectDatabaseInput
            var databaseInput = new CreateProjectDatabaseInput(newProjectInput.ProjectName,
                                                               newProjectInput.ProjectCodeName,
                                                               TempData.Peek("userName").ToString());


            try
            {
                //send the request to the Domain layer
                await _IProjectManagerDomain.CreateNewProject(databaseInput);

                resultList.Errors.Add($"Project: {databaseInput.ProjectName} Project CodeName: {databaseInput.ProjectCodeName} has been created. Please assign the project to indivduals to being working on it.");
                TempData.Add("CreateProjectSuccess", resultList.Errors);
            }
            catch (Exception)
            {
                resultList.Errors.Add("The ProjectName or ProjectCodeName is already in use in the system. Please use another one.");
                TempData.Add("CreateProjectError", resultList.Errors);
                return(RedirectTo("ProjectManager", "CreateProject"));
            }


            return(RedirectTo("ProjectManager", "CreateProject"));
        }
Esempio n. 4
0
        public ActionResult Create()
        {
            CreateProjectInput viewModel = new CreateProjectInput();

            try
            {
                viewModel.ErrorCode        = ErrorCodeHelper.None;
                viewModel.ErrorDescription = "";
            }
            catch (Exception e)
            {
                viewModel.ErrorCode        = ErrorCodeHelper.Error;
                viewModel.ErrorDescription = "Error al obtener datos.";
            }
            return(PartialView("_createPartial", viewModel));
        }
        public void Create(CreateProjectInput input)
        {
            var @entity = Project.Create(input.Name, input.Code, input.Description, input.StartDate, input.FinalDate,
                                         input.EstadoProyecto, input.CreatorUserId, input.CostCenter, input.CompanyName);

            if (@entity == null)
            {
                throw new UserFriendlyException("No se pudo crear el Proyecto.");
            }

            if (_projectManager.ProjectExist(@entity.Name, input.Id, input.CompanyName))
            {
                throw new UserFriendlyException("Existe un Proyecto con el mismo Nombre.");
            }
            _projectRepository.Insert(@entity);
        }
Esempio n. 6
0
        public async Task Export(Proposal proposal, string sourceId)
        {
            var fundingSourceResult = await _projectDb2Client.GetFundingSource.ExecuteAsync(sourceId);

            fundingSourceResult.EnsureNoErrors();

            if (fundingSourceResult.Data !.FundingSource == null)
            {
                var createFundingSourceResult = await _projectDb2Client.CreateFundingSource.ExecuteAsync(sourceId, $"Placeholder for {proposal.Title}");

                createFundingSourceResult.EnsureNoErrors();
            }

            var projectInput = new CreateProjectInput
            {
                FundingSource = sourceId,
                Title         = proposal.Title,
                Owner         = proposal.OwnerId,
                Start         = proposal.StartDate.GetValueOrDefault(),
                End           = proposal.EndDate.GetValueOrDefault().AddMonths(24)
            };

            if (proposal.CustomQuota)
            {
                projectInput.OverrulingQuotaGiB = proposal.CustomQuotaAmount;
            }

            projectInput.Experimenters = proposal.Experimenters.Select((experimenter) => experimenter.UserId).ToList();

            projectInput.Experiments = proposal.Labs
                                       .Select(lab =>
            {
                var(modalityId, withStructuralMri) = ParseModalityId(_labProvider.GetProjectDb2Id(lab.Modality));

                return(new CreateProjectInput_Experiment
                {
                    Modality = modalityId,
                    NumSessions = lab.SessionCount.GetValueOrDefault(),
                    NumSubjects = lab.SubjectCount.GetValueOrDefault(),
                    SessionDurationMinutes = (int)lab.SessionDuration.GetValueOrDefault().TotalMinutes,
                    WithStructuralMri = withStructuralMri
                });
            })
                                       .ToList();

            projectInput.Members = proposal.StorageAccessRules
                                   .Select(rule => new CreateProjectInput_Member
            {
                Username = rule.UserId,
                Role     = GetProjectMemberRole(rule.Role)
            })
                                   .ToList();

            var ethicalApproval = new CreateProjectInput_EthicalApproval();

            if (proposal.EcApproved)
            {
                ethicalApproval.Name   = proposal.EcCode;
                ethicalApproval.Status = EthicalApprovalStatus.Approved;
            }
            else
            {
                ethicalApproval.Name   = proposal.EcReference;
                ethicalApproval.Status = EthicalApprovalStatus.Pending;
            }
            projectInput.EthicalApprovals = new List <CreateProjectInput_EthicalApproval> {
                ethicalApproval
            };

            var result = await _projectDb2Client.ExportProject.ExecuteAsync(proposal.ProjectId, projectInput);

            result.EnsureNoErrors();

            // proposal.ProjectId = result.Data!.CreateProject.Number;
        }