public async Task <ActionResult <AgentJourneyPlanView> > updateJourneyPlan(AgentJourneyPlanView agentJourneyPlanView) { AgentOrderStatus agentOrderStatus = _context.AgentOrderStatus.Where(obj => obj.Id == agentJourneyPlanView.agentOrderStatusId).FirstOrDefault(); agentOrderStatus.OrderStatusId = 2; agentOrderStatus.AgentTargetStatusId = 1; agentOrderStatus.StartDate = System.DateTime.Parse(agentJourneyPlanView.startDate); agentOrderStatus.EndDate = System.DateTime.Parse(agentJourneyPlanView.endDate); _context.AgentOrderStatus.Update(agentOrderStatus); _context.SaveChangesAsync(); var data = (from user in _context.Users join userrole in _context.UserRoles on user.Id equals userrole.UserId join role in _context.Roles on userrole.RoleId equals role.Id where role.Name == "sale agent" join distagent in _context.DistributorAgents on user.Id equals distagent.UserId where distagent.DistributorId == agentJourneyPlanView.distId join agentcus in _context.AgentCustomer on user.Id equals agentcus.SaleAgentId join agentordstat in _context.AgentOrderStatus on agentcus.Id equals agentordstat.AgentCustomerId join tartype in _context.TargetStatusType on agentordstat.AgentTargetStatusId equals tartype.Id join ordertype in _context.OrderStatusType on agentordstat.OrderStatusId equals ordertype.Id //join //orderprod in _context.OrderProducts on agentordstat.Id equals orderprod.AgentOrderStatusId join invent in _context.Inventory on // orderprod.InventoryId equals invent.Id join Prod in _context.Products on invent.ProductId equals Prod.Id select new { agentObject = user, CustomerName = (from customer in _context.Users where customer.Id == agentcus.CustomerId select new { customerObject = customer }).FirstOrDefault(), TargetType = tartype.Type, OrderType = ordertype.OrderStatus } ).ToList(); // status = "success"; return(Ok(new { AgentJourneyPlanStatus = "UpdateSuccess", distributorAgentCustomerDetailList = data })); }
public async Task <ActionResult <AgentJourneyPlanView> > CreateAgentJourneyPlan(AgentJourneyPlanView agentJourneyPlanView) { List <int> customerIdList = new List <int>(); int agentId = _context.Users.Where(obj => obj.FirstName + ' ' + obj.LastName == agentJourneyPlanView.saleAgentName).FirstOrDefault().Id; // string status = ""; for (int i = 0; i < agentJourneyPlanView.customerNameList.Count; i++) { AgentOrderStatus agentOrderStatus = new AgentOrderStatus(); agentOrderStatus.AgentCustomerId = getAgentCustomerId(agentJourneyPlanView.customerNameList[i], agentId); agentOrderStatus.StartDate = System.DateTime.Parse(agentJourneyPlanView.startDate); agentOrderStatus.EndDate = System.DateTime.Parse(agentJourneyPlanView.endDate); agentOrderStatus.AgentTargetStatusId = 1; agentOrderStatus.OrderStatusId = 1; _context.AgentOrderStatus.Add(agentOrderStatus); await _context.SaveChangesAsync(); } var data = (from user in _context.Users join userrole in _context.UserRoles on user.Id equals userrole.UserId join role in _context.Roles on userrole.RoleId equals role.Id where role.Name == "sale agent" join distagent in _context.DistributorAgents on user.Id equals distagent.UserId where distagent.DistributorId == agentJourneyPlanView.distId join agentcus in _context.AgentCustomer on user.Id equals agentcus.SaleAgentId join agentordstat in _context.AgentOrderStatus on agentcus.Id equals agentordstat.AgentCustomerId join tartype in _context.TargetStatusType on agentordstat.AgentTargetStatusId equals tartype.Id join ordertype in _context.OrderStatusType on agentordstat.OrderStatusId equals ordertype.Id //join //orderprod in _context.OrderProducts on agentordstat.Id equals orderprod.AgentOrderStatusId join invent in _context.Inventory on // orderprod.InventoryId equals invent.Id join Prod in _context.Products on invent.ProductId equals Prod.Id select new { agentObject = user, CustomerName = (from customer in _context.Users where customer.Id == agentcus.CustomerId select new { customerObject = customer }).FirstOrDefault(), TargetType = tartype.Type, OrderType = ordertype.OrderStatus } ).ToList(); // status = "success"; return(Ok(new { AgentJourneyPlanStatus = "SaveSuccess", distributorAgentCustomerDetailList = data })); // return Ok(new { AgentJourneyPlanStatus = status }); }