public ActionResult Create(ProjectDocEditModel viewModel) { UserProfile theUser = _service.GetUser(_security.GetUserId(User.Identity.Name)); if (ModelState.IsValid) { ProjectDocument toCreate = new ProjectDocument { CompanyId = theUser.CompanyId, Name = viewModel.Name, Notes = viewModel.Notes, ProjectId = viewModel.ProjectId, Url = viewModel.Url }; if (_service.Create(toCreate)) { // send notifications to invited members int[] invitees = _notice.GetInvitationsNotDeclined(viewModel.ProjectId, theUser.CompanyId).Select(s => s.SentToId).ToArray(); for (int i = 0; i < invitees.Length; i++) { _notice.SendNotification(invitees[i], RecipientType.company, NotificationType.ProjectChange, viewModel.ProjectId, EntityType.Project); } return RedirectToAction("Details", new { id = toCreate.Id }); } else { Util.MapValidationErrors(_service.ValidationDic, this.ModelState); } } return View(viewModel); }
public ActionResult Create(int projectId) { UserProfile theUser = _service.GetUser(_security.GetUserId(User.Identity.Name)); BCModel.Projects.Project theProject = _service.GetProject(projectId); if (!_service.UserIsInvitedToProject(theUser.CompanyId, theProject.Id)) throw new HttpException(403, "user is not invited to project"); ProjectDocEditModel viewModel = new ProjectDocEditModel(); viewModel.ProjectId = projectId; viewModel.CompanyId = theUser.CompanyId; viewModel.ProjectTitle = theProject.Title; return View(viewModel); }
public ActionResult Edit(ProjectDocEditModel viewModel) { if (ModelState.IsValid) { UserProfile theUser = _service.GetUser(_security.GetUserId(User.Identity.Name)); ProjectDocument toUpdate = _service.Get(viewModel.Id); if (theUser.CompanyId != toUpdate.CompanyId) { throw new HttpException(403, "this is not your document"); } toUpdate.Notes = viewModel.Notes; toUpdate.Name = viewModel.Name; toUpdate.Url = viewModel.Url; if (_service.Update(toUpdate)) { // send notifications to invited members int[] invitees = _notice.GetInvitationsNotDeclined(viewModel.ProjectId, theUser.CompanyId).Select(s => s.SentToId).ToArray(); for (int i = 0; i < invitees.Length; i++) { _notice.SendNotification(invitees[i], RecipientType.company, NotificationType.ProjectChange, viewModel.ProjectId, EntityType.Project); } return RedirectToAction("Details", new { id = toUpdate.Id }); } else { Util.MapValidationErrors(_service.ValidationDic, this.ModelState); } } return View(viewModel); }
public ActionResult Edit(int id) { ProjectDocument doc = _service.Get(id); UserProfile theUser = _service.GetUser(_security.GetUserId(User.Identity.Name)); if (doc.CompanyId != theUser.CompanyId) { throw new HttpException(403, "this is not your document"); } ProjectDocEditModel viewModel = new ProjectDocEditModel { CompanyId = doc.CompanyId, Id = doc.Id, Name = doc.Name, Notes = doc.Notes, ProjectId = doc.ProjectId, ProjectTitle = doc.Project.Title, Url = doc.Url }; return View(viewModel); }