public ActionResult Edit(int id) { var _context = new ApplicationDbContext(); var task = _context.Tasks.SingleOrDefault(t => t.TaskId == id); if (task == null) { return(HttpNotFound()); } var viewModel = new TasksFormViewModel(task) { TaskTypes = _context.TaskTypes.ToList(), TaskCategories = _context.TaskCategories.ToList(), Prices = _context.Prices.ToList(), Companies = _context.Companies.ToList(), TaskStatuses = _context.TaskStatuses.ToList(), Members = _context.Members.ToList() }; if (User.IsInRole("CanAddTasks")) { return(View("TaskFormEdit", viewModel)); } else { return(View("ReadOnlyTaskForm", viewModel)); } }
public ActionResult NewFromTemplate(int id) { var sqlDirect = new PrepareTemplate(); var taskId = sqlDirect.InsertTemplate(id); var task = _context.Tasks.SingleOrDefault(t => t.TaskId == taskId); if (task == null) { return(HttpNotFound()); } var viewModel = new TasksFormViewModel(task) { TaskTypes = _context.TaskTypes.ToList(), TaskCategories = _context.TaskCategories.ToList(), Prices = _context.Prices.ToList(), Companies = _context.Companies.ToList(), TaskStatuses = _context.TaskStatuses.ToList(), Members = _context.Members.ToList() }; return(View("TaskFormNewFromTemplate", viewModel)); }
// GET: Tasks public async Task <ActionResult> Index(int id) { await AuthorizeUserInIdentity(); var viewModel = new TasksFormViewModel(); if (id == 0) { viewModel.FilterBy = "Task Index"; } else { var company = new Companies(); company = _context.Companies.SingleOrDefault(c => c.CompanyId == id); viewModel.FilterBy = company.CompanyName; viewModel.FilterId = id; } if (User.IsInRole("CanAddTasks")) { return(View("Index", viewModel)); } else { return(View("ReadOnlyIndex", viewModel)); } }
public ActionResult Save(TasksFormViewModel taskViewModel) { MailMessage msg = new MailMessage(); msg.Body = taskViewModel.EmailBody; msg.Subject = taskViewModel.TaskName; msg.To.Add(new MailAddress(taskViewModel.EmailSendee)); //get attachments string[] stringSeparators = new string[] { ";" }; string[] result = taskViewModel.FileNames.Split(stringSeparators, StringSplitOptions.None); foreach (string file in result) { if (file != "") { Attachment attach = new Attachment(Server.MapPath("~/UploadedFiles/Attachments/" + file)); msg.Attachments.Add(attach); } } SendMail(msg); //save to Task var task = new Tasks(); //KLUDGE - temp code task.PriceId = 2; task.TaskCategoryId = 1; task.TaskTypeId = 9; task.TaskStatusId = 4; task.TaskName = taskViewModel.TaskName; task.TimeWorked = taskViewModel.TimeWorked; task.CompanyId = taskViewModel.CompanyId; task.DateCreated = DateTime.Today; task.DateDue = DateTime.Today; task.DateWorkStarted = DateTime.Today; task.CreatedByAction = "email"; _context.Tasks.Add(task); _context.SaveChanges(); var newVM = new TasksFormViewModel() { TaskTypes = _context.TaskTypes.ToList(), TaskCategories = _context.TaskCategories.ToList(), Prices = _context.Prices.ToList(), Companies = _context.Companies.ToList(), TaskStatuses = _context.TaskStatuses.ToList(), Members = _context.Members.ToList(), PrevMailStatus = true }; return(View("SendEmailForm", newVM)); }
public ViewResult New() { var viewModel = new TasksFormViewModel() { TaskTypes = _context.TaskTypes.ToList(), TaskCategories = _context.TaskCategories.ToList(), Prices = _context.Prices.ToList(), Companies = _context.Companies.ToList(), TaskStatuses = _context.TaskStatuses.ToList(), Members = _context.Members.ToList() }; return(View("TaskFormNew", viewModel)); }
public ActionResult New() { var viewModel = new TasksFormViewModel() { TaskTypes = _context.TaskTypes.ToList(), TaskCategories = _context.TaskCategories.ToList(), Prices = _context.Prices.ToList(), Companies = _context.Companies.ToList(), TaskStatuses = _context.TaskStatuses.ToList(), Members = _context.Members.ToList(), PrevMailStatus = false }; return(View("SendEmailForm", viewModel)); }
public ActionResult New(string subject, string sendee, string caller) { var viewModel = new TasksFormViewModel() { TaskTypes = _context.TaskTypes.ToList(), TaskCategories = _context.TaskCategories.ToList(), Prices = _context.Prices.ToList(), Companies = _context.Companies.ToList(), TaskStatuses = _context.TaskStatuses.ToList(), Members = _context.Members.ToList(), PrevMailStatus = false, TaskName = subject, EmailSubject = subject, EmailSendee = sendee, EmailViewCaller = caller }; return(View("SendEmailForm", viewModel)); }
// GET: Tasks public ActionResult Index(int id) { var viewModel = new TasksFormViewModel(); if (id == 0) { viewModel.FilterBy = "Task Index"; } else { var company = new Companies(); company = _context.Companies.SingleOrDefault(c => c.CompanyId == id); viewModel.FilterBy = company.CompanyName; viewModel.FilterId = id; } return(View(viewModel)); }
public ActionResult TaskFromExternal(string taskName, string taskDesc, string type, int id) { var viewModel = new TasksFormViewModel() { TaskTypes = _context.TaskTypes.ToList(), TaskCategories = _context.TaskCategories.ToList(), Prices = _context.Prices.ToList(), Companies = _context.Companies.ToList(), TaskStatuses = _context.TaskStatuses.ToList(), Members = _context.Members.ToList(), //pre-fill based on Note CreatedByAction = type, AncestorTaskId = id, TaskName = taskName, TaskDescription = taskDesc, TaskStatusId = 1, //KLUDGE - NotStarted DateCreated = DateTime.Today }; return(View("TaskFormNew", viewModel)); }
public ActionResult Save(Tasks task) { var _context = new ApplicationDbContext(); if (!ModelState.IsValid) { var viewModel = new TasksFormViewModel(task) { TaskTypes = _context.TaskTypes.ToList(), TaskCategories = _context.TaskCategories.ToList(), Prices = _context.Prices.ToList(), Companies = _context.Companies.ToList(), TaskStatuses = _context.TaskStatuses.ToList(), Members = _context.Members.ToList() }; return(View("TaskFormNew", viewModel)); } if (task.TaskId == 0) { _context.Tasks.Add(task); } else { var taskInDb = _context.Tasks.Single(t => t.TaskId == task.TaskId); taskInDb.TaskDescription = task.TaskDescription; taskInDb.Hours = task.Hours; taskInDb.DateCreated = task.DateCreated; taskInDb.TaskTypeId = task.TaskTypeId; taskInDb.TaskCategoryId = task.TaskCategoryId; taskInDb.TaskStatusId = task.TaskStatusId; taskInDb.CompanyId = task.CompanyId; taskInDb.PriceId = task.PriceId; taskInDb.MemberId = task.MemberId; } _context.SaveChanges(); return(RedirectToAction("Index", "Tasks", new { id = 0 })); }