Ejemplo n.º 1
0
 public ActionResult JoinUs()
 {
     try
     {
         var model = new JoinUsViewModel();
         List <SelectListItem> typelst = new List <SelectListItem>
         {
             new SelectListItem
             {
                 Text  = "Select",
                 Value = "0"
             }
         };
         //  model.SpecialityList = GetSpecialityList();
         //model.SubSpecialityList = typelst;
         model.AddressModel.AvailableCountry       = GetCountryList();
         model.AddressModel.AvailableStateProvince = typelst;
         model.AvilableQualification = GetAvilableQualifications();
         ViewBag.GenderList          = GetGender();
         return(View(model));
     }
     catch { throw; }
 }
Ejemplo n.º 2
0
        public async Task <ActionResult> JoinUs(JoinUsViewModel model)
        {
            try
            {
                if (model.PictureId == 0)
                {
                    ModelState.AddModelError("upload picture !!", "");
                    ErrorNotification("upload picture !!");
                }
                if (ModelState.IsValid)
                {
                    var user = new ApplicationUser
                    {
                        UserName                  = model.Email,
                        Email                     = model.Email,
                        LastName                  = model.LastName,
                        FirstName                 = model.FirstName,
                        LastIpAddress             = "192.168.225.1",
                        IsEmailUnsubscribed       = false,
                        IsPhoneNumberUnsubscribed = false,
                        LastLoginDateUtc          = DateTime.UtcNow,
                        CreatedOnUtc              = DateTime.UtcNow,
                        PhoneNumber               = model.PhoneNumber,
                        TwoFactorEnabled          = false
                    };
                    var result = await UserManager.CreateAsync(user, "Test@123");

                    if (result.Succeeded)
                    {
                        var dateOfBirth = model.ParseDateOfBirth();
                        await this.UserManager.AddToRoleAsync(user.Id, "Doctor");

                        var doctor = new Doctor
                        {
                            DoctorId           = user.Id,
                            RegistrationNumber = model.RegistrationNumber,
                            Gender             = model.Gender,
                            DateOfBirth        = dateOfBirth.ToString(),
                            Expertise          = (model.Expertise.Any()) ? string.Join(",", model.Expertise) : string.Empty,
                            MiddleName         = model.MiddleName,
                            Subscription       = model.Subscription
                        };
                        _doctorService.AddDoctor(doctor);
                        var address = new Address
                        {
                            StateProvinceId = model.AddressModel.StateProvinceId,
                            CountryId       = model.AddressModel.CountryId,
                            Address1        = model.AddressModel.Address1,
                            Address2        = model.AddressModel.Address2,
                            Hospital        = model.AddressModel.Hospital,
                            FaxNumber       = model.AddressModel.FaxNumber,
                            PhoneNumber     = model.AddressModel.LandlineNumber,
                            Website         = model.AddressModel.Website,
                            ZipPostalCode   = model.AddressModel.ZipPostalCode,
                            City            = model.AddressModel.City
                        };

                        if (address.CountryId == 0)
                        {
                            address.CountryId = null;
                        }
                        if (address.StateProvinceId == 0)
                        {
                            address.StateProvinceId = null;
                        }

                        string state = address.StateProvinceId == 0
                            ? string.Empty
                            : _stateProvinceService.GetStateProvinceById(model.AddressModel.StateProvinceId).Name;
                        string docAddress    = model.AddressModel.Address1 + ", " + model.AddressModel.City + ", " + state + ", " + model.AddressModel.ZipPostalCode;
                        var    geoCoodrinate = GetGeoCoordinate(docAddress);
                        if (geoCoodrinate.Count == 2)
                        {
                            address.Latitude  = geoCoodrinate[AppInfra.Constants.Lat];
                            address.Longitude = geoCoodrinate[AppInfra.Constants.Lng];
                        }
                        else
                        {
                            var geoCoodrinates = GetGeoCoordinate(model.AddressModel.ZipPostalCode);
                            if (geoCoodrinates.Count == 2)
                            {
                                address.Latitude  = geoCoodrinates[AppInfra.Constants.Lat];
                                address.Longitude = geoCoodrinates[AppInfra.Constants.Lng];
                            }
                        }
                        _addressService.AddAddress(address);

                        if (model.PictureId > 0 && !string.IsNullOrWhiteSpace(doctor.DoctorId))
                        {
                            AddPicture(model.PictureId, 0, null, null, doctor.DoctorId);
                        }

                        await UserManager.SendEmailAsync(user.Id, "Thanks for the registration. We'll verify your details.", "For more queries drops us a email on <b>[email protected]</b>");

                        return(RedirectToAction("ThanksJoinUs", "Account"));
                    }
                    if (!string.IsNullOrWhiteSpace(result.Errors.LastOrDefault()))
                    {
                        ErrorNotification(result.Errors.LastOrDefault());
                    }
                }
                List <SelectListItem> typelst = new List <SelectListItem>
                {
                    new SelectListItem
                    {
                        Text  = "Select",
                        Value = "0"
                    }
                };
                model.AddressModel.AvailableCountry       = GetCountryList();
                model.AddressModel.AvailableStateProvince = typelst;
                ViewBag.GenderList = GetGender();
                return(View(model));
            }
            catch (Exception)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError));
            }
        }