예제 #1
0
    public bool Update(int userId, string firstName = "", string lastName = "", string status = "", int themeId = 0, Location home = null, Location work = null)
    {
        if (User.Where(s => s.Id == userId).Count() > 0)
        {
            User userUpdated = User.Where(w => w.Id == userId).First();

            userUpdated.FirstName = !string.IsNullOrEmpty(firstName) ? firstName : userUpdated.FirstName;
            userUpdated.LastName  = !string.IsNullOrEmpty(lastName) ? lastName : userUpdated.LastName;
            userUpdated.Status    = !string.IsNullOrEmpty(status) ? status : userUpdated.Status;
            userUpdated.ThemeId   = (themeId != 0 && UserTheme.Where(w => w.Id == themeId).Count() > 0) ? themeId : userUpdated.ThemeId;

            SaveChanges();

            if (home != null)
            {
                UserLocation homeUpdated = UserLocation.Where(w => w.Id == userUpdated.HomeId).First();

                homeUpdated.Latitude  = home.Latitude;
                homeUpdated.Longitude = home.Longitude;

                SaveChanges();
            }
            if (work != null)
            {
                if (userUpdated.WorkId != 0)
                {
                    UserLocation workUpdated = UserLocation.Where(w => w.Id == userUpdated.WorkId).First();

                    workUpdated.Latitude  = home.Latitude;
                    workUpdated.Longitude = home.Longitude;

                    SaveChanges();
                }
                else
                {
                    UserLocation workLoc = new UserLocation
                    {
                        IsHome    = true,
                        IsWork    = false,
                        Longitude = home.Longitude,
                        Latitude  = home.Latitude
                    };

                    workLoc = UserLocation.Add(workLoc);

                    SaveChanges();

                    userUpdated.WorkId = workLoc.Id;

                    SaveChanges();
                }
            }

            return(true);
        }


        return(true);
    }
예제 #2
0
    public List <UserLocation> Getlocations(int id)
    {
        User user = User.Where(w => w.Id == id).FirstOrDefault();

        UserLocation home = UserLocation.Where(w => w.Id == user.HomeId).FirstOrDefault();

        UserLocation work = UserLocation.Where(w => w.Id == user.WorkId).FirstOrDefault();

        var locations = new List <UserLocation>();

        locations.Add(home);

        if (work != null)
        {
            locations.Add(work);
        }

        return(locations);
    }