public async Task <GenericResponseDTO <int> > DeleteTimeEntry(int id) { var currentUserId = authHelper.GetCurrentUserId(User); var results = new GenericResponseDTO <int>() { Success = false }; var entry = await database.TimeEntries .AsQueryable() .SingleOrDefaultAsync(x => x.User.Id == currentUserId && x.Id == id); if (entry == null) { results.Message = "Could not find the Time Entry"; return(results); } database.TimeEntries.Remove(entry); await database.SaveChangesAsync(); results.Success = true; results.Data = entry.Id; return(results); }
public async Task <GenericResponseDTO <int> > UpdateProjectDetails(ProjectDetailsDTO projectDetails) { var currentUserId = authHelper.GetCurrentUserId(User); var response = new GenericResponseDTO <int>() { Success = false }; Project project = await database.Projects .AsQueryable() .FirstOrDefaultAsync(x => x.Id == projectDetails.ProjectId && x.Teacher.Id == currentUserId && x.ArchivedDate == null); if (project == null) { return(new GenericResponseDTO <int>() { Message = "Couldn't find the project", Success = false }); } project.Description = projectDetails.Description; await database.SaveChangesAsync(); response.Success = true; response.Data = project.Id; return(response); }
public async Task <GenericResponseDTO <int> > UpdateTime(TimeEntryDTO data) { var results = new GenericResponseDTO <int>() { Success = true }; var currentUserId = authHelper.GetCurrentUserId(User); var currentTimeEntry = await database .TimeEntries .AsQueryable() .SingleOrDefaultAsync(x => x.Id == data.Id && x.User.Id == currentUserId); if (currentTimeEntry == null) { results.Success = false; results.Message = "Could not find the specified time entry"; return(results); } currentTimeEntry.Day = data.Day; currentTimeEntry.Length = data.Length; currentTimeEntry.Notes = data.Notes; currentTimeEntry.Day = data.Day; currentTimeEntry.LastModified = DateTime.UtcNow; await database.SaveChangesAsync(); results.Data = currentTimeEntry.Id; return(results); }
public GenericResponseDTO GetAll() { List <TipoCubrimiento> tipoCubrimientos = new List <TipoCubrimiento>(); PolizaFacade entryFacade = new PolizaFacade(); GenericResponseDTO result = entryFacade.GetAllTypesCoverage(); return(result); }
public GenericResponseDTO GetAll() { List <TipoRiesgo> tiposRiesgo = new List <TipoRiesgo>(); PolizaFacade entryFacade = new PolizaFacade(); GenericResponseDTO result = entryFacade.GetAllTypesRisk(); return(result); }
public async Task <ActionResult> PostNewCart([FromBody] UserIdDTO u) { //TODO: Seperation of concern //TODO: Exception handling Order o = new Order(); GenericResponseDTO genericResponseDTO = new GenericResponseDTO(); //Check if user exists if (u.UserId != 0) { try { await _context.users.FirstAsync(x => x.UserId == u.UserId); } catch { genericResponseDTO.Message = "No user with that ID found"; return(NotFound(genericResponseDTO)); } o.UserId = u.UserId; } else { o.UserId = 1; } _context.orders.Add(o); await _context.SaveChangesAsync(); // Generate an idempotency token to ensure our requests are only handled once, in case of connection issues, etc. o.IdempotencyToken = Guid.NewGuid().ToString(); Random rand = new Random(); int itemAmount = rand.Next(5); List <Item> items = await _context.items.Where(x => x.Active == true).ToListAsync(); List <Item> cart = new List <Item>(); for (int i = 0; i < itemAmount; i++) { Random rdm = new Random(); int index = rdm.Next(items.Count()); cart.Add(items[index]); OrderItem tempOrderItem = new OrderItem(o.OrderId, items[index].ItemId); _context.orderItems.Add(tempOrderItem); } await _context.SaveChangesAsync(); CartDTO cartToReturn = new CartDTO(o.OrderId, cart); return(Ok(cartToReturn)); }
public async Task <GenericResponseDTO <int> > CreateProject(ProjectCreateDTO newProject) { var currentUser = await authHelper.GetCurrentUser(User, database); var response = new GenericResponseDTO <int>() { Success = false }; // Project validation if (string.IsNullOrWhiteSpace(newProject.ClientName)) { response.Message = "A project must have a client name."; return(response); } if (string.IsNullOrWhiteSpace(newProject.ProjectName)) { response.Message = "A project must have a project name."; return(response); } // Create the tags var tags = new List <Tag>(); if (newProject.Tags != null) { newProject.Tags.ForEach(x => tags.Add(new Tag() { Name = x })); } // Create the new project object var project = new Project() { ClientName = newProject.ClientName, Description = newProject.Description, CreatedTime = DateTime.UtcNow, Name = newProject.ProjectName, Teacher = currentUser, InviteCode = Guid.NewGuid().ToString(), Tags = tags, Students = new List <User>() }; await database.AddAsync(project); await database.SaveChangesAsync(); response.Success = true; response.Data = project.Id; return(response); }
public async Task AddUserToProjectOnLogin() { await TestAuthHelpers.LogInUser(database, configuration, projectController); ProjectCreateDTO projectInfo = new ProjectCreateDTO { ProjectName = "Soup Delivery Website", ClientName = "Soup Delivery LLC" }; GenericResponseDTO <int> createProjectResponse = await projectController.CreateProject(projectInfo); Assert.IsTrue(createProjectResponse.Success); int projectID = createProjectResponse.Data; Project project = await database.Projects .AsNoTracking() .FirstOrDefaultAsync(p => p.Id == projectID); string projectInviteCode = project.InviteCode; UserDTO registrationInfo = new UserDTO { Email = "*****@*****.**", Password = "******", FirstName = "Suzuya", LastName = "Z." }; GenericResponseDTO <int> registerResponse = await authController.Register(registrationInfo); Assert.IsTrue(registerResponse.Success); UserDTO loginInfo = new UserDTO { Email = "*****@*****.**", Password = "******", InviteCode = projectInviteCode }; await authController.Login(loginInfo); User user = await database.Users .Include(x => x.Projects) .FirstOrDefaultAsync(u => u.Id == registerResponse.Data); Assert.IsTrue(user.Projects.Count == 1); Assert.IsTrue(user.Projects[0].Id == project.Id); }
public async Task <ActionResult> UpdateActiveStatus(int id) { Order order = new Order(); GenericResponseDTO genericResponseDTO = new GenericResponseDTO(); //Check if order exist try { order = await _context.orders.FirstOrDefaultAsync(x => x.OrderId == id); } catch { genericResponseDTO.Message = "No order with the gice id exist"; return(NotFound(genericResponseDTO)); } order.Active = !order.Active; List <OrderItem> orderItemList = await _context.orderItems.Where(x => x.OrderId == id).ToListAsync(); foreach (OrderItem oi in orderItemList) { oi.Active = !order.Active; } _context.Entry(order).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { throw; } genericResponseDTO.Message = "Active id was successfully changed"; return(Ok(genericResponseDTO)); }
public async Task <ActionResult> ChangeOrderStatus([FromBody] ChangeOrderStatusDTO cos) { GenericResponseDTO genericResponseDTO = new GenericResponseDTO(); Order o = new Order(); //Check if order exist try { o = await _context.orders.FirstOrDefaultAsync(x => x.OrderId == cos.OrderId); } catch { genericResponseDTO.Message = "No order with that order Id exist"; return(NotFound(genericResponseDTO)); } //Check if status is valid if (cos.Status >= 0 && cos.Status <= 4) { o.Status = (Statuses)cos.Status; } else { genericResponseDTO.Message = "The status is not valid. Try one of the following:" + "\n0. In progress" + "\n1. Accepted" + "\n2. Declined" + "\n3. Cart"; return(BadRequest(genericResponseDTO)); } _context.Entry(o).State = EntityState.Modified; await _context.SaveChangesAsync(); genericResponseDTO.Message = "Order status was successfully changed"; return(Ok(genericResponseDTO)); }
public JsonResult Create(Poliza vm) { if (ModelState.IsValid) { try { GenericResponseDTO response = polizaFacade.CreatePoliza(vm); return(SerializeAndSendResponse(response)); } catch (Exception ex) { return(SerializeAndSendResponse(new GenericResponseDTO() { OperationSuccess = false, ErrorMessage = ex.Message.ToString() })); } } return(SerializeAndSendResponse(new GenericResponseDTO() { OperationSuccess = false })); }
public async Task <GenericResponseDTO <int> > CreateTime(TimeEntryDTO data) { var results = new GenericResponseDTO <int>() { Success = true }; var newTimeEntry = new TimeEntry() { CreatedTime = DateTime.UtcNow, Day = data.Day, LastModified = DateTime.UtcNow, Length = data.Length, Notes = data.Notes, Project = await database.Projects.AsQueryable().SingleAsync(x => x.Id == data.ProjectId), User = await authHelper.GetCurrentUser(User, database) }; database.TimeEntries.Add(newTimeEntry); await database.SaveChangesAsync(); results.Data = newTimeEntry.Id; return(results); }
public async Task <GenericResponseDTO <DateTime?> > ArchiveProject(ArchiveProjectDTO archiveDetails) { var currentUserId = authHelper.GetCurrentUserId(User); var response = new GenericResponseDTO <DateTime?>() { Success = true }; Project archivingProject = await database.Projects .AsQueryable() .Where(x => x.Id == archiveDetails.ProjectId) .Where(x => x.Teacher.Id == currentUserId) .FirstOrDefaultAsync(); if (archivingProject == null) { response.Success = false; response.Message = "Could not find the project"; return(response); } if (archiveDetails.Archive) { archivingProject.ArchivedDate = DateTime.UtcNow; } else { archivingProject.ArchivedDate = null; } await database.SaveChangesAsync(); response.Data = archivingProject.ArchivedDate; return(response); }