public async Task <IActionResult> EditTask(string id) { ViewBag.userMenu = GetMenu(); if (!checkuser()) { return(RedirectToAction("Index", "Home")); } if (id == null) { return(NotFound()); } var Task = await context.Task.SingleOrDefaultAsync(m => m.TaskId == id); var e = new CreateTaskInputModel() { ProjectNumber = Task.ProjectNumber, TaskId = Task.TaskId, TaskName = Task.TaskName, TaskStart = Task.TaskStart, TaskEnd = Task.TaskEnd, }; ViewData["naemtask"] = Task.TaskName; if (Task == null) { return(NotFound()); } return(PartialView("EditTask", e)); }
public async Task <IActionResult> Create(CreateTaskInputModel inputModel, int id) { inputModel.CaseId = id; if (!ModelState.IsValid) { // Populate drop-down menus' options and return create page to edit data and re-submit inputModel.TaskTypes = await tasksService.GetAllTaskTypesAsync(); inputModel.TaskStatuses = await tasksService.GetAllTaskStatusesAsync(); return(View(inputModel)); } string userId = usersService.UserManager.GetUserId(User); int createResult = await tasksService.CreateTaskAsync(inputModel, userId); if (createResult > 0) { await usersService.UpdateUserLastActivityDateAsync(userId); TempData["TaskCreatedSuccessfully"] = true; return(LocalRedirect($"/Cases/ViewUpdate/{inputModel.CaseId}#tasks-table")); } return(View("Error", new ErrorViewModel())); }
public IHttpResponse Create(CreateTaskInputModel model) { if (this.User.Role != Role.Admin.ToString()) { return(this.BadRequestError("You do not have permission to access this functionality!")); } if (string.IsNullOrWhiteSpace(model.Title)) { return(this.BadRequestErrorWithView("Please enter title!")); } if (string.IsNullOrWhiteSpace(model.Description)) { return(this.BadRequestErrorWithView("Please enter description!")); } if (string.IsNullOrWhiteSpace(model.Participants)) { return(this.BadRequestErrorWithView("Please enter participants!")); } model.AffectedSectors = new List <SectorType>(); // to ugly but... no other way to do it easy if (model.CustomersSector != null) { System.Enum.TryParse(model.CustomersSector, out SectorType sectorType); model.AffectedSectors.Add(sectorType); } if (model.FinancesSector != null) { System.Enum.TryParse(model.FinancesSector, out SectorType sectorType); model.AffectedSectors.Add(sectorType); } if (model.InternalSector != null) { System.Enum.TryParse(model.InternalSector, out SectorType sectorType); model.AffectedSectors.Add(sectorType); } if (model.ManagementSector != null) { System.Enum.TryParse(model.ManagementSector, out SectorType sectorType); model.AffectedSectors.Add(sectorType); } if (model.MarketingSector != null) { System.Enum.TryParse(model.MarketingSector, out SectorType sectorType); model.AffectedSectors.Add(sectorType); } if (this.TaskService.CreateTask(model) == null) { return(this.BadRequestErrorWithView("Something went wrong when trying to create album in database.")); } return(this.Redirect("/Home/Index")); }
public async Task <IActionResult> Create() { CreateTaskInputModel model = new CreateTaskInputModel { // Populate drop-down menus' options TaskTypes = await tasksService.GetAllTaskTypesAsync(), TaskStatuses = await tasksService.GetAllTaskStatusesAsync(), }; return(View(model)); }
public async Task <string> CreateTaskAsync(CreateTaskInputModel inputModel, string ownerId, string companyId) { var task = new TaskModel { Name = inputModel.Name, StartDate = inputModel.StartDate, EndDate = inputModel.EndDate, Description = inputModel.Description, OwnerId = ownerId, CompanyId = companyId, }; foreach (var participant in inputModel.Participants) { await this.userTasks.AddAsync(new UserTask { TaskId = task.Id, UserId = participant, }); } if (inputModel.Subtasks.Where(x => x != null).Any()) { foreach (var subtask in inputModel.Subtasks.Where(x => x != null)) { await this.subtasks.AddAsync(new Subtask { TaskId = task.Id, ShortDescription = subtask, }); } } await this.tasks.AddAsync(task); var subaskResult = await this.subtasks.SaveChangesAsync(); var userTasksResult = await this.userTasks.SaveChangesAsync(); var taskResult = await this.tasks.SaveChangesAsync(); if (taskResult < 0 || subaskResult < 0 || userTasksResult < 0) { throw new InvalidOperationException("Exception happened in TaskService while saving the Task in IDeletableEntityRepository<Task>"); } else { return(task.Id); } }
public async Task CreateTaskAsyncShouldCreateTaskWithSubtasksAndParticipantsSeccessfully() { var usersForDb = new List <ApplicationUser> { new ApplicationUser { FirstName = "Ivan", LastName = "Ivanov", Email = "*****@*****.**", UserName = "******", PasswordHash = "sjeigjsdfhsf" }, new ApplicationUser { FirstName = "Petur", LastName = "Ivanov", Email = "*****@*****.**", UserName = "******", PasswordHash = "sjeigjsdfhsf" }, new ApplicationUser { FirstName = "Owner", LastName = "Owner", Email = "*****@*****.**", UserName = "******", PasswordHash = "sjeigjsdfhsf" }, }; var companyForDb = new Company { Name = "Test Company", CompanyPicture = new Picture { Url = "url" } }; await this.dbContext.Users.AddRangeAsync(usersForDb); await this.dbContext.Companies.AddAsync(companyForDb); await this.dbContext.SaveChangesAsync(); var createInputModel = new CreateTaskInputModel { Name = "Test", StartDate = DateTime.UtcNow, EndDate = DateTime.UtcNow.AddDays(3), Description = "Test desc", Participants = new List <string> { usersForDb[0].Id, usersForDb[1].Id }, Subtasks = new List <string> { "subTask1", "subTask2" }, }; await this.service.CreateTaskAsync(createInputModel, usersForDb[2].Id, companyForDb.Id); Assert.Equal(1, await this.dbContext.Tasks.CountAsync()); Assert.Equal(2, this.dbContext.Tasks.FirstAsync().Result.Participants.Count); Assert.Equal(2, this.dbContext.Tasks.FirstAsync().Result.Subtasks.Count); Assert.Equal(companyForDb.Id, this.dbContext.Tasks.FirstAsync().Result.CompanyId); }
public IActionResult Create(CreateTaskInputModel model) { if (!this.ModelState.IsValid.HasValue || !this.ModelState.IsValid.Value) { this.Model.Data["Error"] = "Invalid input. Please fill all inputs."; return(this.RedirectToAction("/Tasks/Create")); } model.AffectedSectors = new List <SectorType>(); // to ugly but... no other way to do it easy if (model.CustomersSector != null) { System.Enum.TryParse(model.CustomersSector, out SectorType sectorType); model.AffectedSectors.Add(sectorType); } if (model.FinancesSector != null) { System.Enum.TryParse(model.FinancesSector, out SectorType sectorType); model.AffectedSectors.Add(sectorType); } if (model.InternalSector != null) { System.Enum.TryParse(model.InternalSector, out SectorType sectorType); model.AffectedSectors.Add(sectorType); } if (model.ManagementSector != null) { System.Enum.TryParse(model.ManagementSector, out SectorType sectorType); model.AffectedSectors.Add(sectorType); } if (model.MarketingSector != null) { System.Enum.TryParse(model.MarketingSector, out SectorType sectorType); model.AffectedSectors.Add(sectorType); } if (this.TaskService.CreateTask(model) == null) { this.Model.Data["Error"] = "Something went wrong when trying to create album in database."; return(this.RedirectToAction("/Tasks/Create")); } //TODO: add success message handle in viewEngine!!! this.Model.Data["Success"] = "Successfully create album in database."; return(this.RedirectToAction("/Home/Index")); }
public IHttpResponse Create(CreateTaskInputModel model) { var task = new Task() { Title = model.Title, Description = model.Description, DueDate = model.DueDate, Participants = model.Participants, AffectedSectors = model.AffectedSectors }; this.Db.Tasks.Add(task); this.Db.SaveChanges(); return(this.Redirect("/Tasks/Details?id=" + task.Id)); }
public async Task <IActionResult> EditTask(string id, CreateTaskInputModel editModel) { var loggedInUser = HttpContext.User; var loggedInUserName = loggedInUser.Identity.Name; ViewBag.userMenu = GetMenu(); var query = (from x in context.Task where x.TaskId.Equals(editModel.TaskId) select x).FirstOrDefault(); if (editModel.TaskId != query.TaskId) { return(NotFound()); } if (ModelState.IsValid) { try { //context.Update(ord); var addquery = from test in context.Task where test.TaskId.Equals(editModel.TaskId) select test; foreach (Models.Task UserUpdate in addquery) { UserUpdate.TaskName = editModel.TaskName; UserUpdate.TaskEnd = editModel.TaskEnd; UserUpdate.TaskStart = editModel.TaskStart; } await context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { throw; } var segment = query.ProjectNumber.ToString(); return(RedirectToAction("CreateTask", "ProjectManagement", new RouteValueDictionary( new { Controller = "ProjectManagement", Action = "CreateTask", id = segment }))); } return(View(query.TaskId)); }
public async Task <int> CreateTaskAsync(CreateTaskInputModel inputModel, string userId) { CaseTask taskToAdd = new CaseTask { CreatedOn = DateTime.UtcNow, UserId = userId, CaseId = inputModel.CaseId, TypeId = inputModel.TypeId, StatusId = inputModel.StatusId, Action = inputModel.Action, NextAction = inputModel.NextAction, Comments = inputModel.Comments, }; dbContext.Tasks.Add(taskToAdd); int saveResult = await dbContext.SaveChangesAsync(); return(saveResult); }
public async Task <IActionResult> Create(CreateTaskInputModel inputModel) { var companyId = this.companyService.GetIdByUserName(this.User.Identity.Name); if (!this.ModelState.IsValid) { var employees = await this.userService.GetUsersInCompanyInViewModelAsync <EmployeesDropdownViewModel>(companyId); inputModel.Employees = employees; return(this.View(inputModel)); } var ownerId = this.userManager.GetUserId(this.User); await this.taskService.CreateTaskAsync(inputModel, ownerId, companyId); return(this.RedirectToAction(nameof(this.Index))); }
public Task CreateTask(CreateTaskInputModel model) { var task = new Task() { Title = model.Title, Description = model.Description, DueDate = model.DueDate, IsReported = false, Participants = model.Participants, }; this.db.Tasks.Add(task); var affectedSectors = new List <TaskSector>(); foreach (var modelAffectedSector in model.AffectedSectors) { var taskSector = new TaskSector() { Sector = modelAffectedSector, TaskId = task.Id }; this.db.TaskSectors.Add(taskSector); affectedSectors.Add(taskSector); } try { this.db.SaveChanges(); } catch (Exception e) { Console.WriteLine(e); return(null); } return(task); }
public async Task <IActionResult> Create([FromBody] CreateTaskInputModel inputModel) { await _taskAppService.Create(inputModel); return(Response()); }
public async Task <IActionResult> CreateTask(string pnum, CreateTaskInputModel inputModel) { if (!ModelState.IsValid) { return(View()); } ViewBag.userMenu = GetMenu(); if (inputModel.TaskEnd < inputModel.TaskStart) { ModelState.AddModelError("ErrorCreateTask", "กรุณากรอกเวลาใหม่"); return(View()); } try { var id = (from u in context.RunningNumber where u.Type.Equals("TaskID") select u).FirstOrDefault(); int num; if (id.Number == null) { num = 100001; } else { num = Convert.ToInt32(id.Number); num = num + 1; } Models.Task ord = new Models.Task { ProjectNumber = inputModel.ProjectNumber, TaskId = num.ToString(), TaskName = inputModel.TaskName, TaskStart = inputModel.TaskStart, TaskEnd = inputModel.TaskEnd }; // Add the new object to the Orders collection. context.Task.Add(ord); await context.SaveChangesAsync(); var query = from xx in context.RunningNumber where xx.Type.Equals("TaskId") select xx; foreach (RunningNumber RunTaskID in query) { RunTaskID.Number = num.ToString(); } // Submit the changes to the database. try { await context.SaveChangesAsync(); } catch (Exception e) { Console.WriteLine(e); // Provide for exceptions. } return(RedirectToAction("CreateTask", "ProjectManagement")); } catch (Exception ex) { var message = ex.Message; return(View()); } }
public async Task<Unit> Create(CreateTaskInputModel createTaskInputModel) { return await _mediatorService.SendCommand( _mapper.Map<CreateTaskCommand>(createTaskInputModel)); }