コード例 #1
0
        public ActionResult AddProject(AddProjectModel addProject)
        {
            if (ModelState.IsValid)
            {
                var icon    = GetIcon();
                var command = new AddProjectsCommand
                {
                    File         = icon,
                    Name         = addProject.Name,
                    ClientName   = addProject.ClientName,
                    Status       = addProject.Status,
                    StartDate    = addProject.StartDate,
                    ProjectOwner = addProject.ProjectOwner,
                    Description  = addProject.Description
                };

                var result = mediator.Send(command);

                if (result == true)
                {
                    return(RedirectToAction("ProjectManagement", "Admin"));
                }

                return(RedirectToAction("AddProject", new { message = TimesheetReport.Controllers.ManageController.ManageMessageId.Error }));
            }

            return(RedirectToAction("ProjectManagement"));
        }
コード例 #2
0
        public async Task <bool> AddProjectAsync(AddProjectModel addProject)
        {
            using (SqlConnection conn = GetConnection())
            {
                conn.Open();
                var transaction = conn.BeginTransaction();
                try
                {
                    DynamicParameters param = new DynamicParameters();
                    if (addProject.ProjectId > 0)
                    {
                        param.Add("@ProjectId", addProject.ProjectId);
                    }
                    param.Add("@Name", addProject.Name);
                    param.Add("@Description", addProject.Description);
                    param.Add("@StartDate", addProject.StartDate);
                    param.Add("@DueDate", addProject.DueDate);
                    param.Add("@CreatedBy", addProject.CreatedBy);
                    param.Add("@Priority", addProject.Priority);
                    int ProjectId = await transaction.Connection.ExecuteScalarAsync <int>("sp_AddProject", param, transaction : transaction, commandType : CommandType.StoredProcedure);

                    if (addProject.Filelist.Count > 0)
                    {
                        foreach (var item in addProject.Filelist)
                        {
                            param = new DynamicParameters();
                            param.Add("@ProjectId", ProjectId);
                            param.Add("@DisplayFileName", item.DisplayFileName);
                            param.Add("@FileName", item.FileName);
                            param.Add("@Path", item.Path);
                            await transaction.Connection.ExecuteScalarAsync <int>("sp_AddProjectDocument", param, transaction : transaction, commandType : CommandType.StoredProcedure);
                        }
                    }
                    if (addProject.UsersId != null && addProject.UsersId.Count() > 0)
                    {
                        param = new DynamicParameters();
                        param.Add("@ProjectId", ProjectId);
                        await transaction.Connection.ExecuteScalarAsync <int>("sp_DeleteProjectUser", param, transaction : transaction, commandType : CommandType.StoredProcedure);

                        foreach (var item in addProject.UsersId)
                        {
                            param = new DynamicParameters();
                            param.Add("@ProjectId", ProjectId);
                            param.Add("@UserId", item);
                            await transaction.Connection.ExecuteScalarAsync <int>("sp_AddProjectUser", param, transaction : transaction, commandType : CommandType.StoredProcedure);
                        }
                    }
                    transaction.Commit();

                    return(true);
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    return(false);
                }
            }
        }
コード例 #3
0
        public JsonResult Add([FromBody] AddProjectModel model)
        {
            if (!ModelState.IsValid)
            {
                var errors = ModelState.Values.Select(k => k.Errors).ToList();
                return(Json(new { success = false, error = errors }));
            }

            return(Json(new { Added = _projects.Add(model.title, model.description, model.teamId, model.categoryId, model.parentId), success = true }));
        }
コード例 #4
0
        public async Task <IActionResult> AddProjects()
        {
            AddProjectModel addProject = new AddProjectModel();
            var             result     = await this._repository.GetUsersAsync(3);

            addProject.Users = result.Select(x => new SelectListItem {
                Text = x.FirstName + " " + x.LastName, Value = x.Id.ToString()
            }).ToList();
            return(View(addProject));
        }
コード例 #5
0
        public async Task <IActionResult> Create(AddProjectModel model,
                                                 IFormCollection image1, IFormCollection image2, IFormCollection image3, IFormCollection image4)
        {
            string storePath = "/images/project/";
            var    path1     = Path.Combine(
                Directory.GetCurrentDirectory(), "wwwroot", "images", "project",
                image1.Files[0].FileName);
            var path2 = Path.Combine(
                Directory.GetCurrentDirectory(), "wwwroot", "images", "project",
                image2.Files[0].FileName);
            var path3 = Path.Combine(
                Directory.GetCurrentDirectory(), "wwwroot", "images", "project",
                image3.Files[0].FileName);
            var path4 = Path.Combine(
                Directory.GetCurrentDirectory(), "wwwroot", "images", "project",
                image4.Files[0].FileName);

            using (var stream = new FileStream(path1, FileMode.Create))
            {
                await image1.Files[0].CopyToAsync(stream);
            }
            using (var stream = new FileStream(path2, FileMode.Create))
            {
                await image2.Files[0].CopyToAsync(stream);
            }
            using (var stream = new FileStream(path3, FileMode.Create))
            {
                await image3.Files[0].CopyToAsync(stream);
            }
            using (var stream = new FileStream(path4, FileMode.Create))
            {
                await image4.Files[0].CopyToAsync(stream);
            }
            var project = new Projects
            {
                Title    = model.Title,
                ProjDesc = model.ProjDesc,
                GitRepo  = model.GitRepo,
                Status   = model.ProjectStatus,
                PImage1  = storePath + model.Image1.FileName,
                PImage2  = storePath + model.Image2.FileName,
                PImage3  = storePath + model.Image3.FileName,
                PImage4  = storePath + model.Image4.FileName,
            };
            await _projectService.Create(project);

            return(RedirectToAction("Index", "Project"));
        }
コード例 #6
0
        public async Task AddProjectAsync(AddProjectModel model)
        {
            if (await _projectRepository.ExistedAsync(m => m.Name.Equals(model.Name)))
            {
                throw new MateralConfigCenterException("名称已存在");
            }
            var project = model.CopyProperties <Project>();

            _protalServerUnitOfWork.RegisterAdd(project);
            _protalServerUnitOfWork.RegisterAdd(new Namespace
            {
                Name        = "Application",
                Description = "默认命名空间",
                ProjectID   = project.ID
            });
            await _protalServerUnitOfWork.CommitAsync();
        }
コード例 #7
0
        public async Task <ResultModel> AddProject(AddProjectModel model)
        {
            try
            {
                await projectService.AddProjectAsync(model);

                return(ResultModel.Success("添加成功"));
            }
            catch (AspectInvocationException ex)
            {
                return(ResultModel.Fail(ex.InnerException?.Message));
            }
            catch (MateralConfigCenterException ex)
            {
                return(ResultModel.Fail(ex.Message));
            }
        }
コード例 #8
0
        //POST : /api/ProjectBoard/AddProject
        public async Task <Object> AddProject(AddProjectModel model)
        {
            if (model.ProjectTitle != null)
            {
                Project project = new Project {
                    ProjectTitle = model.ProjectTitle
                };
                await _context.Projects.AddAsync(project);

                await _context.SaveChangesAsync();

                return(Ok());
            }
            else
            {
                return(BadRequest(new { message = "Project title is null." }));
            }
        }
コード例 #9
0
        public ActionResult AddProject(AddProjectModel addProject)
        {
            if (null == addProject)
            {
                return(View("Error"));
            }

            var name = addProject.Name;

            if (string.IsNullOrWhiteSpace(name))
            {
                return(View("Error"));
            }

            var desc = addProject.Description;

            if (string.IsNullOrWhiteSpace(desc))
            {
                desc = null;
            }

            using (var db = new BuildVersioningDataContext())
            {
                if (db.Projects.Any(p => string.Compare(p.Name, name, StringComparison.OrdinalIgnoreCase) == 0))
                {
                    return(View("Error"));                    // <-- A project with the same name already exists.
                }
                var project =
                    new Project
                {
                    Name                   = name,
                    Description            = desc,
                    BuildNumber            = 0,
                    DateBuildNumberUpdated = DateTime.Now
                };

                db.Projects.Add(project);
                db.SaveChanges();
            }

            return(RedirectToRoute("ListProjects"));
        }
コード例 #10
0
        public async Task <IActionResult> AddProject(string projectId, string description, DateTime startDate, DateTime endDate)
        {
            if (string.IsNullOrEmpty(projectId))
            {
                return(RedirectToAction("Add", "Project", new { message = "Please input full information!!!" }));
            }
            if (string.IsNullOrEmpty(description))
            {
                return(RedirectToAction("Add", "Project", new { message = "Please input full information!!!" }));
            }
            HttpClient client = new HttpClient();
            string     token  = HttpContext.Session.GetString("userToken");

            client.DefaultRequestHeaders.Add("Authorization", "Bearer " + token);
            AddProjectModel model = new AddProjectModel()
            {
                Description      = description,
                EndDate          = endDate,
                ProjectCompanyId = projectId,
                StartDate        = startDate
            };

            var content = _responseAPI.GetContent <AddProjectModel>(model);

            HttpResponseMessage rs = await client.PostAsync(_responseAPI.APIHost + "api/Project", content);

            string message = "";

            if (rs.IsSuccessStatusCode)
            {
                message = "Successfully!!";
            }
            else if (rs.ReasonPhrase.Equals("Conflict"))
            {
                message = "Project exist";
            }
            else
            {
                message = "Invalid Date";
            }
            return(RedirectToAction("Add", "Project", new { message = message }));
        }
コード例 #11
0
        public async Task <JsonResult> Add([FromBody] AddProjectModel model)
        {
            if (model.title.Length < 5 || model.title.Length > 50)
            {
                throw new Exception("Неверная длина названия проекта");
            }

            if (model.description.Length > 250)
            {
                throw new Exception("Неверная длина описания проекта");
            }

            int userId = int.Parse(User.Identity.Name);

            var addedProject = await _dbContext.AddAsync(new Project
            {
                Title       = model.title,
                Description = model.description
            })
                               .ConfigureAwait(false);

            await _dbContext.SaveChangesAsync(true)
            .ConfigureAwait(false);

            await _dbContext.AddAsync(new LinkedProject
            {
                Accepted  = true,
                ProjectId = addedProject.Entity.Id,
                RoleId    = 3,
                UserId    = userId
            })
            .ConfigureAwait(false);


            await _dbContext.SaveChangesAsync(true)
            .ConfigureAwait(false);

            return(new JsonResult(new ProjectUpdateResponse {
                project = addedProject.Entity
            }));
        }
コード例 #12
0
ファイル: ProjectController.cs プロジェクト: qquser/Project1
        public async Task <IActionResult> Post(AddProjectModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (model.CommandId == Guid.Empty)
            {
                model.CommandId = NewId.NextGuid();
            }

            var command = new AddProjectCommand(model);

            await Send(command);

            return(Accepted(new PostResult <AddProjectCommand>()
            {
                CommandId = model.ProjectId,
                Timestamp = command.Timestamp
            }));
        }
コード例 #13
0
#pragma warning disable 1998
        public async Task <IActionResult> AddProject([FromBody] AddProjectModel project)
#pragma warning restore 1998
        {
            if (!this.ModelState.IsValid || project == null)
            {
                this.TempData["error"] = "Incorrect input.";
                return(this.Json(this.Url.Action("AddProject")));
            }

            try
            {
                var validator = new SchemaValidator();

                var errors = validator.ValidateManifest(project.EmptyManifestXml, out XDocument _);

                if (errors.Count > 0)
                {
                    this.TempData["error"] = "Schema validation errors:\r\n" + string.Join("\r\n", errors);
                    return(this.Json(this.Url.Action("AddProject")));
                }
                else
                {
                    ProjectInfo projectInfo = ManifestDeserializer.DeserializeProjectInfo(XElement.Parse(project.EmptyManifestXml));

                    var upsertedProject = await this.repositoryService.Upsert(projectInfo).ConfigureAwait(false);

                    this.TempData["success"] = $"Added project to catalog. Internal ID: {upsertedProject.Id}";

                    return(this.Json(this.Url.Action("AddProject")));
                }
            }
            catch (Exception ex)
            {
                this.TempData["error"] = $"Error: {ex.Message}";
                return(this.Json(this.Url.Action("AddProject")));
            }
        }
コード例 #14
0
        public async Task <IActionResult> AddProjects(AddProjectModel addProject)
        {
            DateTime start = DateTime.ParseExact(addProject.StartDate, "MM/dd/yyyy", CultureInfo.InvariantCulture);
            DateTime due   = DateTime.ParseExact(addProject.DueDate, "MM/dd/yyyy", CultureInfo.InvariantCulture);

            if (start > due)
            {
                ViewBag.Error = "Due Date must be higher than start date";
                var result = await this._repository.GetUsersAsync(3);

                addProject.Users = result.Select(x => new SelectListItem {
                    Text = x.FirstName + " " + x.LastName, Value = x.Id.ToString()
                }).ToList();
                return(View(addProject));
            }
            string path         = this._env.WebRootPath + "/Project";
            string filname      = "";
            string fullfilepath = "";

            addProject.Filelist = new List <ProjectFileModel>();
            if (addProject.files != null && addProject.files.Count > 0)
            {
                foreach (var formFile in addProject.files)
                {
                    if (formFile.Length > 0)
                    {
                        if (!Directory.Exists(path))
                        {
                            Directory.CreateDirectory(path);
                        }
                        filname      = Guid.NewGuid().ToString() + "." + formFile.FileName.Split(".").LastOrDefault();
                        fullfilepath = Path.Combine(path, filname);
                        using (var stream = new FileStream(fullfilepath, FileMode.Create))
                        {
                            await formFile.CopyToAsync(stream);
                        }
                        addProject.Filelist.Add(new ProjectFileModel
                        {
                            Path            = fullfilepath,
                            DisplayFileName = formFile.FileName,
                            FileName        = filname
                        });
                    }
                }
            }
            addProject.CreatedBy = this.UserId;

            if (await this._repository.AddProjectAsync(addProject))
            {
                if (addProject.ProjectId > 0)
                {
                    ViewBag.Success = "Project is added";
                }
                else
                {
                    ViewBag.Success = "Project is updated";
                }
            }
            else
            {
                ViewBag.Error = "Some error occured while saving.";
            }
            return(View(addProject));
        }
コード例 #15
0
ファイル: ProjectController.cs プロジェクト: qquser/Project1
 public AddProjectCommand(AddProjectModel model)
 {
     _model    = model;
     Timestamp = DateTime.UtcNow;
 }
コード例 #16
0
        public ActionResult AddProject()
        {
            var viewModel = new AddProjectModel();

            return(View(viewModel));
        }
コード例 #17
0
 public void Post([FromBody] AddProjectModel value)
 {
 }