public async Task <ActionResult> Create(HttpPostedFileBase[] Documents, ProjectTeamViewModel collection) { try { string employees = string.Join(",", Request["Employees"]); ModelState.Remove("Id"); ModelState.Remove("Documents"); ModelState.Remove("EmployeeId"); ModelState.Remove("CurrentlyWorking"); if (ModelState.IsValid) { collection.Documents = ""; //foreach (HttpPostedFileBase file in Documents) //{ // if (file != null) // { // var filename = Path.GetFileName(file.FileName); // collection.Documents = collection.Documents + " " + filename; // var serverpath = Path.Combine(Server.MapPath("~/ProjectDocuments/") + filename); // file.SaveAs(serverpath); // } //} //ViewBag.Employees = await APIHelpers.GetAsync<List<Employee>>("api/Employee/GetEmployees"); For when redirect to same view this statement is ndeeded for Employee Dropdown if (collection.Id == Guid.Empty) { //var data = await APIHelpers.PostAsync<Projects>("api/Project/Post", collection); //collection.Id = data.Id; await APIHelpers.PostAsync <Projects>("api/Project/Post", collection); TempData["sucess"] = ProjectResources.create; } else { collection.EmployeeId = employees; await APIHelpers.PutAsync <Projects>("api/Project/Put", collection); TempData["sucess"] = ProjectResources.update; } return(RedirectToAction("Index")); //return View("Create", collection); //For redirect to same view } else { return(View(collection)); } } catch (Exception ex) { return(View()); } }
// GET: Project/Create public async Task <ActionResult> Create() { try { ProjectTeamViewModel model = new ProjectTeamViewModel(); List <Employee> emps = await APIHelpers.GetAsync <List <Employee> >("api/Employee/GetEmployeesByRole/" + EmployeeManagementSystem.Helper.CommonHelper.EmployeeRoleId()); ViewBag.Employees = emps.Select(_ => new Employee() { UserId = _.UserId, FirstName = _.FirstName + " " + _.MiddleName + " " + _.LastName }); return(View(new ProjectTeamViewModel())); } catch (Exception ex) { return(RedirectToAction("AccessDenied", "Error")); } }
public Projects Put(ProjectTeamViewModel model) { try { Projects pro = new Projects { Id = model.Id, Name = model.Name, Description = model.Description, ProjectStatus = model.ProjectStatus, ProjectType = model.ProjectType, Documents = model.Documents }; var updatedata = _repository.Update(pro); return(updatedata); } catch (Exception ex) { throw; } }
public Projects Post(ProjectTeamViewModel model) { try { Projects pro = new Projects { Id = Guid.NewGuid(), Name = model.Name, Description = model.Description, ProjectStatus = model.ProjectStatus, ProjectType = model.ProjectType, Documents = model.Documents }; var data = _repository.Insert(pro); return(data); } catch (Exception ex) { throw; } }