public IActionResult AddLocation(LocationPerson locationPerson)
 {
     db.LocationPerson.Add(locationPerson);
     db.SaveChanges();
     return(RedirectToAction("Index", "Location"));
 }
Esempio n. 2
0
        Data GetLocationSupervisor(string token)
        {
            var objData = new Data
            {
                Locations   = new List <Location>(),
                Supervisors = new List <Supervisor>(),
                TeamLeads   = new List <TeamLead>()
            };
            var locations     = new List <Location>();
            var supervisors   = new List <Supervisor>();
            var teamLeads     = new List <TeamLead>();
            var data          = new LocationPerson();
            var nextpageToken = string.Empty;
            var url           = UrlBuilder(ApiTypeEnum.Locations);

            do
            {
                if (!string.IsNullOrEmpty(nextpageToken))
                {
                    url = AppendNextPageToken(url, nextpageToken);
                }

                data          = GetResponse <LocationPerson>(token, url);
                nextpageToken = data.next_pagetoken;
                foreach (var item in data.items)
                {
                    var location_Name  = string.Empty;
                    var supervisorName = string.Empty;
                    var teamLeadName   = string.Empty;
                    var locationId     = string.Empty;
                    var supervisorId   = string.Empty;
                    var teamLeadId     = string.Empty;

                    foreach (var attribute in item.attributes)
                    {
                        switch (attribute.typename)
                        {
                        case "CSL Work Address - City":
                            location_Name = attribute.value;
                            locationId    = attribute.type_guid;
                            break;

                        case "CSL Team Lead":
                            teamLeadName = attribute.value;
                            teamLeadId   = attribute.type_guid;
                            break;

                        case "CSL Supervisor":
                            supervisorName = attribute.value;
                            supervisorId   = attribute.type_guid;
                            break;

                        default:
                            break;
                        }
                    }

                    if (!locations.Any(i => i.Name.Trim().ToLower() == location_Name.Trim().ToLower()))
                    {
                        locations.Add(new Location {
                            Id = locationId, Name = location_Name, Color = "white"
                        });
                    }

                    if (!supervisors.Any(i => i.Name.Trim().ToLower() == supervisorName.Trim().ToLower()))
                    {
                        supervisors.Add(new Supervisor {
                            Id = supervisorId, Name = supervisorName, Color = "white"
                        });
                    }

                    if (!teamLeads.Any(i => i.Name.Trim().ToLower() == teamLeadName.Trim().ToLower()))
                    {
                        teamLeads.Add(new TeamLead {
                            Id = teamLeadId, Name = teamLeadName, Color = "white"
                        });
                    }
                }

                objData.Locations.AddRange(locations.OrderBy(i => i.Name).ToList());
                objData.Supervisors.AddRange(supervisors.OrderBy(i => i.Name).ToList());
                objData.TeamLeads.AddRange(teamLeads.OrderBy(i => i.Name).ToList());
            } while (!string.IsNullOrEmpty(data.next_pagetoken));


            return(objData);
        }