Beispiel #1
0
 public HttpStatusCode Insert(Location loc)
 {
     if (ModelState.IsValid)
     {
         Adapter.LocationRepository.Insert(loc);
         Adapter.Save();
         return HttpStatusCode.Created;
     }
     throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.BadRequest));
 }
        public HttpResponseMessage Insert(Company comp)
        {
            var l = new RadarModels.Location();

            l.Street  = comp.Location.Street;
            l.Number  = comp.Location.Number;
            l.Box     = comp.Location.Box;
            l.Zipcode = comp.Location.Zipcode;
            l.City    = comp.Location.City;
            l.Country = comp.Location.Country;
            IGeocoder geocoder = new GoogleGeocoder();

            Address[] addresses = geocoder.Geocode(l.Street + " " + l.Number + ", " + l.Zipcode + " " + l.City + ", " + l.Country).ToArray();
            if (addresses.Length != 0 && addresses[0].Coordinates != null)
            {
                l.Latitude  = Convert.ToDecimal(addresses[0].Coordinates.Latitude);
                l.Longitude = Convert.ToDecimal(addresses[0].Coordinates.Longitude);

                Adapter.LocationRepository.Insert(l);
                Adapter.Save();
            }
            else
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, new Exception("Address not found")));
            }

            comp.Location    = l;
            comp.CreatedDate = DateTime.Now;
            Adapter.CompanyRepository.Insert(comp);
            Adapter.Save();

            Employee emp = new Employee();

            emp.CompanyId   = comp.CompanyId;
            emp.UserId      = comp.UserId;
            emp.CreatedDate = DateTime.Now;
            emp.RoleId      = Adapter.RoleRepository.GetByID(4).RoleId;
            Adapter.EmployeeRepository.Insert(emp);
            Adapter.Save();

            return(Request.CreateResponse(HttpStatusCode.OK));
        }
Beispiel #3
0
        public ActionResult RegisterPost(Register model, string redirectUrl)
        {
            ViewBag.redirectUrl = redirectUrl;
            if (ModelState.IsValid)
            {
                var userModel            = model;
                RadarModels.Location loc = new RadarModels.Location();
                loc.Street  = model.Location.Street;
                loc.Number  = model.Location.Number;
                loc.Box     = model.Location.Box;
                loc.Zipcode = model.Location.Zipcode;
                loc.City    = model.Location.City;
                loc.Country = model.Location.Country;
                IGeocoder geocoder  = new GoogleGeocoder();
                Address[] addresses = geocoder.Geocode(loc.Street + " " + loc.Number + ", " + loc.Zipcode + " " + loc.City + ", " + loc.Country).ToArray();
                if (addresses.Length != 0 && addresses[0].Coordinates != null)
                {
                    loc.Latitude  = Convert.ToDecimal(addresses[0].Coordinates.Latitude);
                    loc.Longitude = Convert.ToDecimal(addresses[0].Coordinates.Longitude);
                    Adapter.LocationRepository.Insert(loc);
                    Adapter.Save();
                }
                else
                {
                    ModelState.AddModelError("", "Het adres kon niet worden gevonden.");
                    return(View(model));
                }


                UserMembershipProvider mp = new UserMembershipProvider();

                MembershipCreateStatus status;

                UserMembershipUser mu = mp.CreateUserBetter(model.Username, model.Email, model.Gender?"m":"f", model.Password, model.DateOfBirth, model.Bio, loc.LocationId, out status) as UserMembershipUser;

                if (status == MembershipCreateStatus.DuplicateEmail)
                {
                    ModelState.AddModelError("", "Emailadres heeft al een account.");
                }
                else if (status == MembershipCreateStatus.InvalidPassword)
                {
                    ModelState.AddModelError("", "Paswoord is niet sterk genoeg. Moet minimum 5 karakters zijn.");
                }
                else if (status == MembershipCreateStatus.Success)
                {
                    SendMail(userModel);

                    if (!String.IsNullOrEmpty(redirectUrl))
                    {
                        byte[] b   = Convert.FromBase64String(redirectUrl);
                        string url = System.Text.Encoding.UTF8.GetString(b);
                        return(Redirect(url + "?&message=registered"));
                    }
                    else
                    {
                        return(Redirect("http://localhost:4911/Radar/app/#/?message=registered"));
                    }
                }
            }
            else
            {
                ModelState.AddModelError("", "De ingevulde gegevens zijn niet correct.");
            }
            return(View(model));
        }
Beispiel #4
0
 public HttpStatusCode Update(int id, Location loc)
 {
     if (ModelState.IsValid && id == loc.LocationId)
     {
         Adapter.LocationRepository.Update(loc);
         Adapter.Save();
         return HttpStatusCode.OK;
     }
     throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.BadRequest));
 }
Beispiel #5
0
        public ActionResult RegisterPost(Register model, string redirectUrl)
        {
            ViewBag.redirectUrl = redirectUrl;
            if (ModelState.IsValid)
            {
                var userModel = model;
                RadarModels.Location loc = new RadarModels.Location();
                loc.Street = model.Location.Street;
                loc.Number = model.Location.Number;
                loc.Box = model.Location.Box;
                loc.Zipcode = model.Location.Zipcode;
                loc.City = model.Location.City;
                loc.Country = model.Location.Country;
                IGeocoder geocoder = new GoogleGeocoder();
                Address[] addresses = geocoder.Geocode(loc.Street + " " + loc.Number + ", " + loc.Zipcode + " " + loc.City + ", " + loc.Country).ToArray();
                if (addresses.Length != 0 && addresses[0].Coordinates != null)
                {
                    loc.Latitude = Convert.ToDecimal(addresses[0].Coordinates.Latitude);
                    loc.Longitude = Convert.ToDecimal(addresses[0].Coordinates.Longitude);
                    Adapter.LocationRepository.Insert(loc);
                    Adapter.Save();
                }
                else
                {
                    ModelState.AddModelError("", "Het adres kon niet worden gevonden.");
                    return View(model);
                }

                UserMembershipProvider mp = new UserMembershipProvider();

                MembershipCreateStatus status;

                UserMembershipUser mu = mp.CreateUserBetter(model.Username, model.Email, model.Gender?"m":"f", model.Password,model.DateOfBirth, model.Bio, loc.LocationId, out status) as UserMembershipUser;

                if (status == MembershipCreateStatus.DuplicateEmail)
                    ModelState.AddModelError("", "Emailadres heeft al een account.");
                else if(status == MembershipCreateStatus.InvalidPassword)
                    ModelState.AddModelError("", "Paswoord is niet sterk genoeg. Moet minimum 5 karakters zijn.");
                else if (status == MembershipCreateStatus.Success)
                {
                    SendMail(userModel);

                    if (!String.IsNullOrEmpty(redirectUrl))
                    {
                        byte[] b = Convert.FromBase64String(redirectUrl);
                        string url = System.Text.Encoding.UTF8.GetString(b);
                        return Redirect(url + "?&message=registered");
                    }
                    else
                        return Redirect("http://localhost:4911/Radar/app/#/?message=registered");
                }
            }
            else
            {
                ModelState.AddModelError("", "De ingevulde gegevens zijn niet correct.");
            }
            return View(model);
        }