public ActionResult NewDetails(int id = 0, string message = null)
        {
            if (Request.IsAuthenticated)
            {
                try
                {
                    var placeService = new PlaceService2();

                    MyPlace myweather = mpr.GetWeather(id);
                    string  place     = myweather.place;
                    string  region    = myweather.region;

                    ExtWeather extWeather = placeService.GetWeatherInfo(place, region);
                    extWeather.placeName = myweather.place;

                    ViewBag.longitude = myweather.longitude;
                    ViewBag.latitude  = myweather.latitude;

                    if (myweather == null)
                    {
                        return(RedirectToAction("Error", "NotFound"));
                    }
                    ViewBag.UserMessage = "";
                    return(View(extWeather));
                }
                catch
                {
                    string userMessage = "Sidan kunde inte hämtas pga problem hos extern service";
                    return(RedirectToAction("Index", "MyPlaces", new { message = userMessage }));
                }
            }
            return(RedirectToAction("LogIn", "Account"));
        }
示例#2
0
        public static Profile CreateProfile(ISession session, string username, Country country = null, Gender gender = Gender.NotSet, AccountType accountType = AccountType.Instructor)
        {
            Profile profile1 = new Profile();

            if (country != null)
            {
                profile1.CountryId = country.GeoId;
            }
            profile1.Licence.AccountType            = accountType;
            profile1.Licence.LastPointOperationDate = DateTime.UtcNow;
            profile1.Privacy    = new ProfilePrivacy();
            profile1.Settings   = new ProfileSettings();
            profile1.Gender     = gender;
            profile1.UserName   = username;
            profile1.Email      = username + "@wfg.pl";
            profile1.DataInfo   = new DataInfo();
            profile1.Birthday   = DateTime.Now.Date;
            profile1.Statistics = new ProfileStatistics();
            session.SaveOrUpdate(profile1.Statistics);
            session.SaveOrUpdate(profile1);
            ProfileDTO dto = profile1.Map <ProfileDTO>();

            profile1.Tag = dto;

            MyPlace defaultPlace = new MyPlace();

            defaultPlace.IsDefault = true;
            defaultPlace.IsSystem  = true;
            defaultPlace.Profile   = profile1;
            defaultPlace.Color     = Color.Aqua.ToColorString();
            defaultPlace.Name      = "Default";
            session.Save(defaultPlace);
            session.Flush();
            return(profile1);
        }
        public ActionResult Delete(int id = 0)
        {
            if (Request.IsAuthenticated)
            {
                string username   = User.Identity.Name;
                string placeOwner = mpr.GetNewPlaceOwner(id);
                if (placeOwner == username)
                {
                    MyPlace myweather = mpr.GetWeather(id);

                    if (myweather == null)
                    {
                        //Skapa eventuellt en errorsida här.
                        return(HttpNotFound());
                    }
                    return(View(myweather));
                }
                else
                {
                    return(RedirectToAction("Index", "MyPlaces"));
                }
            }

            return(RedirectToAction("LogIn", "Account"));
        }
示例#4
0
        void setIsDefault(MyPlace newDefaultPlace)
        {
            var defaultPlace = Session.QueryOver <MyPlace>().Where(x => x.Profile.GlobalId == SecurityInfo.SessionData.Profile.GlobalId && x.IsDefault).SingleOrDefault();

            defaultPlace.IsDefault    = false;
            newDefaultPlace.IsDefault = true;
            Session.Update(defaultPlace);
        }
示例#5
0
        protected MyPlace CreateMyPlace(string name, Profile profile, bool notForRecords = false)
        {
            var gym = new MyPlace();

            gym.Name          = name;
            gym.Profile       = profile;
            gym.Color         = Color.Aqua.ToColorString();
            gym.CreationDate  = DateTime.UtcNow;
            gym.NotForRecords = notForRecords;
            insertToDatabase(gym);
            return(gym);
        }
        public void UpdateMyPlace_OtherProfile()
        {
            MyPlace     myPlace = CreateMyPlace("test", profiles[0]);
            var         profile = (ProfileDTO)profiles[1].Tag;
            SessionData data    = CreateNewSession(profile, ClientInformation);

            var dto = myPlace.Map <MyPlaceDTO>();

            dto.Name      = "name";
            dto.ProfileId = profile.GlobalId;
            RunServiceMethod(delegate(InternalBodyArchitectService service)
            {
                service.SaveMyPlace(data.Token, dto);
            });
        }
示例#7
0
        public async Task <object> Delete(object data)
        {
            return(await Task.Run(() =>
            {
                dynamic inData = data.ToDynamicObject();

                string placeId = inData.ID;
                Guid ID = Guid.Parse(placeId);
                MyPlace place = UOW.MyPlacesRepository.Where(p => p.ID == ID).FirstOrDefault();

                UOW.MyPlacesRepository.Delete(place);
                UOW.Commit();

                return ID;
            }));
        }
示例#8
0
        public async Task <object> Insert(object data)
        {
            return(await Task.Run(() =>
            {
                dynamic inData = data.ToDynamicObject();

                MyPlace place = new MyPlace();

                place.ID = Guid.NewGuid();
                place.Name = inData.Name;
                place.UserAccountID = inData.UserAccountID;
                place.Location = UtilGeoGraph.Create((double)inData.Location.Latitude, (double)inData.Location.Longitude);

                UOW.MyPlacesRepository.Insert(place);
                UOW.Commit();

                return place;
            }));
        }
        public ActionResult NewCreate(ViewModel model)
        {
            if (Request.IsAuthenticated)
            {
                if (ModelState.IsValid)
                {
                    MyPlace myweather = new MyPlace();
                    myweather.place = model.place;
                    var placeService2 = new PlaceService2();

                    var username = User.Identity.Name;
                    var place    = myweather.place;
                    var region   = model.region;
                    //Prova att istället här kalla på GetWeatherlist

                    List <MyPlace> weatherlist = new List <MyPlace>();
                    //Weatherlist kollar om användaren redan har platsen.
                    weatherlist = mpr.GetWeatherlist(username, place, region);
                    int number = weatherlist.Count;
                    if (number > 0)
                    {
                        string userMessage = "Din post har inte sparats eftersom platsen redan finns";
                        return(RedirectToAction("Index", "MyPlaces", new { message = userMessage }));
                    }

                    bool exists = placeService2.CheckExistanceYr(place, region);
                    if (exists == false)
                    {
                        //Platsen finns inte
                        string userMessage = "Din post har inte sparats eftersom platsen inte finns på vädersidan";
                        return(RedirectToAction("NewCreate", "MyPlaces", new { message = userMessage }));
                    }

                    var newCoordinates = placeService2.GetNewCoordinates(place, region);

                    if (newCoordinates == null) // || newCoordinates.Count == 0
                    {
                        string userMessage = "Din post har inte sparats eftersom platsen inte finns på geonames";
                        return(RedirectToAction("NewCreate", "MyPlaces", new { message = userMessage }));
                    }

                    //Ska flyttas in i ovanstående if-sats.
                    if (newCoordinates.Count == 0)
                    {
                        return(RedirectToAction("NewCreate", "MyPlaces"));
                    }

                    myweather.longitude   = decimal.Parse(newCoordinates[0], System.Globalization.CultureInfo.InvariantCulture);
                    myweather.latitude    = decimal.Parse(newCoordinates[1], System.Globalization.CultureInfo.InvariantCulture);
                    myweather.region      = region;
                    myweather.projectuser = username;


                    mpr.CreateWeather(myweather);
                    return(RedirectToAction("Index"));
                }

                return(View(model));
            }
            return(RedirectToAction("LogIn", "Account"));
        }