Esempio n. 1
0
 private IndividualDetail PopulateRecord(IndividualVM vm, decimal portalUsersId, string userId)
 {
     return(new IndividualDetail
     {
         PortalUsersID = portalUsersId,
         Email = vm.Email,
         MobileNo = vm.MobileNo,
         TelephoneNo = vm.TelephoneNo,
         GenderId = vm.GenderId,
         DateOfBirth = vm.DateOfBirth,
         MaritalStatusId = vm.MaritalStatusId,
         MilitaryStatus_Id = vm.MilitaryStatus_Id,
         NationalityId = vm.NationalityId,
         PhotoPath = vm.PhotoPath,
         Is_Approved = 1,
         AllowtoViewMyInfo = vm.AllowtoViewMyInfo,
         RejectReason = vm.RejectReason,
         PostDate = DateTime.Now,
         PostUserID = userId,
         IndividualMedicalID = vm.IndividualMedicalID,
         UserID = userId,
         CountryID = vm.CountryID,
         CityID = vm.CityID
     });
 }
Esempio n. 2
0
 public static object PostUpdates(IndividualVM individualObject)
 {
     try
     {
         individualObject.UserID = Utils.LoggedUser.UserId;
         var mr = individualManager.UpdatePersonalInfo(individualObject);
         return(Utils.ServiceResponse(pageCode, mr));
     }
     catch (Exception ex)
     {
         ModelResponse mr = new ModelResponse(new Exception(ex.Message));
         return(Utils.ServiceResponse(pageCode, mr));
     }
 }
Esempio n. 3
0
        public static object Post(IndividualVM individualObject)
        {
            try
            {
                var manager = System.Web.HttpContext.Current.GetOwinContext().GetUserManager <ApplicationUserManager>();
                manager.UserValidator = new UserValidator <ApplicationUser>(manager)
                {
                    AllowOnlyAlphanumericUserNames = false,
                    RequireUniqueEmail             = true
                };
                manager.PasswordValidator = new PasswordValidator()
                {
                    RequireUppercase = false
                };
                IdentityResult userResult;
                var            user = new ApplicationUser()
                {
                    UserName = individualObject.User.UserName, Email = individualObject.User.Email, PhoneNumber = individualObject.User.PhoneNumber
                };
                userResult = manager.Create(user, individualObject.User.Password);
                ModelResponse mr = null;
                if (userResult.Succeeded)
                {
                    mr = individualManager.Post(ref individualObject, user.Id);
                    return(Utils.ServiceResponse(pageCode, mr));
                }
                else
                {
                    if (userResult.Errors.FirstOrDefault().Contains("is already taken"))
                    {
                        mr = new ModelResponse(-4, null);
                    }
                    else
                    {
                        mr = new ModelResponse(new Exception(userResult.Errors.FirstOrDefault()));
                    }


                    return(Utils.ServiceResponse(pageCode, mr));
                }
            }
            catch (Exception ex)
            {
                ModelResponse mr = new ModelResponse(new Exception(ex.Message));
                return(Utils.ServiceResponse(pageCode, mr));
            }
        }
Esempio n. 4
0
        public IndividualVM UpdatePersonalInfo(IndividualVM vm)
        {
            var dbContext = new LMISEntities();

            try
            {
                var individualObject = dbContext.IndividualDetails.Single(i => i.PortalUsersID == vm.PortalUsersID);

                #region 1st: Update portal user

                individualObject.PortalUser.IDNumber = vm.PortalUser.IDNumber;
                individualObject.PortalUser.IDType   = vm.PortalUser.IDType;
                if (individualObject.Email != vm.Email)
                {
                    var user = dbContext.AspNetUsers.Where(u => u.Id == vm.UserID).SingleOrDefault();
                    user.UserName = vm.Email;
                    user.Email    = vm.Email;
                    dbContext.Entry(user).State = EntityState.Modified;
                }

                #endregion

                #region 2nd: Populate Individual object

                individualObject.MobileNo          = vm.MobileNo;
                individualObject.TelephoneNo       = vm.TelephoneNo;
                individualObject.DateOfBirth       = vm.DateOfBirth;
                individualObject.Email             = vm.Email;
                individualObject.MaritalStatusId   = vm.MaritalStatusId;
                individualObject.GenderId          = vm.GenderId;
                individualObject.MilitaryStatus_Id = vm.GenderId == "00200002" ? vm.MilitaryStatus_Id : string.Empty;
                individualObject.NationalityId     = string.IsNullOrEmpty(vm.NationalityId)
                    ? individualObject.NationalityId
                    : vm.NationalityId;
                individualObject.CountryID           = vm.CountryID;
                individualObject.CityID              = vm.CityID;
                individualObject.IndividualMedicalID = vm.IndividualMedicalID;
                individualObject.AllowtoViewMyInfo   = vm.AllowtoViewMyInfo;
                individualObject.UpdateDate          = System.DateTime.Now;
                individualObject.UpdateUserID        = individualObject.AspNetUser.Id;
                individualObject.PhotoPath           = string.IsNullOrEmpty(vm.PhotoPath)
                    ? individualObject.PhotoPath
                    : vm.PhotoPath;
                individualObject.Is_Approved = (int)Approval.Pending;

                #endregion

                #region 3rd: Delete details

                var dr = individualObject.IndividualDetailsDets
                         .Where(r => r.PortalUsersID == vm.PortalUsersID)
                         .ToList();

                dbContext.IndividualDetailsDets.RemoveRange(dr);

                #endregion

                #region 4th: Add translations

                foreach (
                    IndividualTranslationVM translation in
                    vm.Translation.Where(t => t.FirstName != null || t.LastName != null || t.Address != null))
                {
                    IndividualDetailsDet translationObject = new IndividualDetailsDet
                    {
                        PortalUsersID = individualObject.PortalUsersID,
                        LanguageID    = translation.LanguageID,
                        FirstName     = translation.FirstName,
                        LastName      = translation.LastName,
                        Address       = translation.Address
                    };
                    individualObject.IndividualDetailsDets.Add(translationObject);
                }

                #endregion

                #region 5th: Save Individual object

                dbContext.Entry(individualObject).State = EntityState.Modified;

                dbContext.SaveChanges();

                #endregion

                return(vm);
            }
            catch (DbEntityValidationException e)
            {
                foreach (var eve in e.EntityValidationErrors)
                {
                    Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:");
                }
                throw;
            }
            catch
            {
                throw;
            }
        }
Esempio n. 5
0
        public void Post(ref IndividualVM vm, string userId)
        {
            var dbContext = new LMISEntities();

            try
            {
                #region 1st: Add portal user

                PortalUser portalUser = new PortalUser
                {
                    PortalUsersID    = vm.PortalUser.PortalUsersID,
                    IDType           = vm.PortalUser.IDType,
                    IDNumber         = vm.PortalUser.IDNumber,
                    UserCategory     = vm.PortalUser.UserCategory,
                    UserSubCategory  = vm.PortalUser.UserSubCategory,
                    TrainingProvider = vm.PortalUser.TrainingProvider,
                    Employer         = vm.PortalUser.Employer,
                    JobSeeker        = vm.PortalUser.JobSeeker,
                    TrainingSeeker   = vm.PortalUser.TrainingSeeker,
                    Researcher       = vm.PortalUser.Researcher,
                    Internal         = vm.PortalUser.Internal,
                    IsSubscriper     = vm.PortalUser.IsSubscriper
                };
                dbContext.PortalUsers.Add(portalUser);
                dbContext.SaveChanges();

                #endregion


                using (var transaction = dbContext.Database.BeginTransaction())
                {
                    #region 2nd: Populate Individual object

                    IndividualDetail individualObject = PopulateRecord(vm, portalUser.PortalUsersID, userId);
                    individualObject.PostDate = DateTime.UtcNow;

                    #endregion

                    #region trd: Add translations

                    foreach (
                        IndividualTranslationVM translation in
                        vm.Translation.Where(t => t.FirstName != null || t.LastName != null || t.Address != null))
                    {
                        IndividualDetailsDet translationObject = new IndividualDetailsDet
                        {
                            PortalUsersID = portalUser.PortalUsersID,
                            LanguageID    = translation.LanguageID,
                            FirstName     = translation.FirstName,
                            LastName      = translation.LastName,
                            Address       = translation.Address
                        };
                        individualObject.IndividualDetailsDets.Add(translationObject);
                    }

                    #endregion

                    #region 4th: Save Individual object

                    dbContext.IndividualDetails.Add(individualObject);
                    dbContext.SaveChanges();
                    transaction.Commit();

                    #endregion
                }
            }
            catch (DbEntityValidationException e)
            {
                foreach (var eve in e.EntityValidationErrors)
                {
                    //Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                }
                throw;
            }
            catch
            {
                throw;
            }
        }
Esempio n. 6
0
        public ModelResponse UpdatePersonalInfo(IndividualVM vm)
        {
            var result = Repo.UpdatePersonalInfo(vm);

            return(new ModelResponse(0, result));
        }
Esempio n. 7
0
 public ModelResponse Post(ref IndividualVM vm, string userId)
 {
     Repo.Post(ref vm, userId);
     return(new ModelResponse(0, userId));
 }