public void AddShouldAddProjectsCorrectly() { var projectToAdd = new Project() { Id = 5, Name = "John", EstimatedDate = DateTime.Now, Description = "This is my description", GoalMoney = 321312 }; var result = projectService.Add(projectToAdd); Assert.AreEqual(result, projectToAdd.Id); }
public IHttpActionResult Post(SaveProjectRequestModel model) { if (!this.ModelState.IsValid) { return(this.BadRequest(this.ModelState)); } var createdProjectId = projects.Add( model.Name, model.Discription, this.User.Identity.Name, model.Private); return(this.Ok(createdProjectId)); }
public IActionResult Add(ProjectCreateViewModel viewModel) { var result = _projectsService.Add(new AddProjectDto { Name = viewModel.Name, Description = viewModel.Description }); if (result.IsSuccess) { return(RedirectToAction(nameof(ProjectsController.Index), "Projects")); } else { viewModel.ErrorMessage = result.ErrorMessage; return(View(viewModel)); } }
// [ValidateAntiForgeryToken] public JsonResult Create([FromBody] Project a) { if (string.IsNullOrEmpty(a.Title)) { return(new JsonResult(new { message = "ProjectTitleMissing" })); } if (projectsService.GetAll().Any(p => p.Title == a.Title)) { return(new JsonResult(new { message = "ProjectTitleNotUnique" })); } string newProjectId = projectsService.Add(a, HttpContext.User); Project project = projectsService.Get(newProjectId, HttpContext.User); project.ProjectMemberIds = projectsService.GetProjectCreateModel(project.Id, HttpContext.User); project.UsernamesWithIds = projectsService.GetProjectCreateModel(null, HttpContext.User); return(new JsonResult(project)); }
public async Task <IActionResult> Import(IFormFile file) { int TOTAL_INSERT = 0; int TOTAL_UPDATE = 0; var uploads = System.IO.Path.Combine(_environment.WebRootPath, "temp"); file = Request.Form.Files[0]; using (var fileStream = new FileStream(System.IO.Path.Combine(uploads, file.FileName), FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite)) { await file.CopyToAsync(fileStream); try { using (var Stream = new FileStream(System.IO.Path.Combine(uploads, file.FileName), FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite)) { using (ExcelPackage package = new ExcelPackage(Stream)) { ExcelWorksheet worksheet = package.Workbook.Worksheets[1]; int rowCount = worksheet.Dimension.Rows; int ColCount = worksheet.Dimension.Columns; for (int row = 2; row <= rowCount; row++) { if (worksheet.Cells[row, 1].Value != null && worksheet.Cells[row, 2].Value != null && worksheet.Cells[row, 3].Value != null && worksheet.Cells[row, 4].Value != null && worksheet.Cells[row, 5].Value != null && worksheet.Cells[row, 6].Value != null) { var NetworkNumber = worksheet.Cells[row, 1].Value.ToString(); var Project = worksheet.Cells[row, 2].Value.ToString(); var Department = worksheet.Cells[row, 3].Value.ToString(); var LineManager = worksheet.Cells[row, 4].Value.ToString(); var ProjectManager = worksheet.Cells[row, 5].Value.ToString(); var AccountName = worksheet.Cells[row, 6].Value.ToString(); var Description = (worksheet.Cells[row, 7].Value != null) ? worksheet.Cells[row, 7].Value.ToString() : ""; NetworkNumber NetWorkFind = Service .GetAll() .FirstOrDefault(x => _excel.TruncateString(x.Code) == _excel.TruncateString(NetworkNumber)); Projects ProjectFind = projects .GetAll() .FirstOrDefault(x => _excel.TruncateString(x.Name) == _excel.TruncateString(Project)); Departement DepartmentFind = departement .GetAll() .FirstOrDefault(x => _excel.TruncateString(x.Name) == _excel.TruncateString(Department)); UserProfile LineManagerUser = await FindUserByRole(LineManager, "Project Manager"); UserProfile ProjectManagerUser = await FindUserByRole(ProjectManager, "Project Manager"); AccountName AccountFind = accountName .GetAll() .FirstOrDefault(x => _excel.TruncateString(x.Name) == _excel.TruncateString(AccountName.ToString())); if (ProjectFind == null) { Projects pj = new Projects { Name = Project }; ProjectFind = projects.Add(pj); } if (LineManagerUser != null && ProjectManagerUser != null && DepartmentFind != null && AccountName != null) { if (NetWorkFind == null) { NetworkNumber nt = new NetworkNumber { Code = NetworkNumber, Project = ProjectFind, Departement = DepartmentFind, LineManager = LineManagerUser, ProjectManager = ProjectManagerUser, AccountName = AccountFind, Description = Description }; Service.Add(nt); TOTAL_INSERT++; } else { NetworkNumber nt = Service.GetById(NetWorkFind.Id); nt.Project = ProjectFind; nt.Departement = DepartmentFind; nt.LineManager = LineManagerUser; nt.ProjectManager = ProjectManagerUser; nt.AccountName = AccountFind; nt.Description = Description; Service.Update(nt); TOTAL_UPDATE++; } } } } } } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } } TempData["Messages"] = "Total Inserted = " + TOTAL_INSERT + " , Total Updated = " + TOTAL_UPDATE; System.IO.File.Delete(System.IO.Path.Combine(uploads, file.FileName)); return(RedirectToAction("Index")); }