public async Task <IActionResult> CreateTask([FromBody] TaskModel taskModel) { string str = "Create Successfully"; Models.Task task = new Models.Task(); foreach (var item in taskModel.taskData) { task.Title = item.Title; task.Description = item.Description; task.Color = item.Color; task.StartDate = item.StartDate; task.FinishDate = item.FinishDate; task.Hours = item.Hours; task.Priority = item.Priority; task.StatusId = item.StatusId; task.TaskOwnerId = item.TaskOwnerId; task.ProjectId = item.ProjectId; } _context.Task.Add(task); await _context.SaveChangesAsync(); var result = JsonConvert.SerializeObject(new { result = str }); return(Ok(result)); }
public async Task <IActionResult> UpdateUser([FromRoute] int id, [FromBody] UserModel user) { string str = ""; var thisUser = await _context.User.SingleOrDefaultAsync(m => m.Id == id); foreach (var item in user.userData) { if (item.Fullname != null && item.Tagname != null) { thisUser.Fullname = item.Fullname; thisUser.Tagname = item.Tagname; thisUser.Status = item.Status; thisUser.Role = item.Role; thisUser.tokenRegister = item.tokenRegister; } } _context.User.Update(thisUser); try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UserExists(id)) { return(NotFound()); } else { str = "Update success"; } } var result = JsonConvert.SerializeObject(new { result = str }); return(Ok(result)); }
public async Task <IActionResult> UpdateProject([FromRoute] int id, [FromBody] ProjectModel project) { string str = ""; var thisProject = await _context.Project.SingleOrDefaultAsync(m => m.Id == id); foreach (var item in project.projectData) { if (thisProject.Name != null && thisProject.Description != null) { thisProject.Name = item.Name; thisProject.Description = item.Description; thisProject.StartDate = item.StartDate; thisProject.FinishDate = item.FinishDate; thisProject.WorkingTimePerDay = item.WorkingTimePerDay; thisProject.WorkingDayPerWeek = item.WorkingDayPerWeek; thisProject.Color = item.Color; } } _context.Project.Update(thisProject); try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProjectExists(id)) { str = "Project no exists !"; } else { str = "Updated project successfully"; } } var result = JsonConvert.SerializeObject(new { result = str }); return(Ok(result)); }
public async Task <IActionResult> CreateTemplate([FromBody] TemplateModel template) { string str = "Create Successfully"; Template temp = new Template(); foreach (var item in template.templateData) { temp.TemplateName = item.TemplateName; temp.AdminId = item.AdminId; } _context.Template.Add(temp); await _context.SaveChangesAsync(); var result = JsonConvert.SerializeObject(new { result = str }); return(Ok(result)); }