Ejemplo n.º 1
0
        public override Object ResetPassword <T>(T entity)
        {
            BO.User addUserBO = (BO.User)(object) entity;


            if (addUserBO == null)
            {
                return(new BO.ErrorObject {
                    ErrorMessage = "User object can't be null", errorObject = "", ErrorLevel = BO.ErrorLevel.Error
                });
            }
            if (addUserBO.ID == 0)
            {
                return(new BO.ErrorObject {
                    ErrorMessage = "Invalid user id", errorObject = "", ErrorLevel = BO.ErrorLevel.Error
                });
            }

            EO.User userDB = new EO.User();
            EO.UserPasswordActivation invitationDB = new EO.UserPasswordActivation();

            userDB = addUserBO.ID > 0 ? _context.Users.Where(p => p.ID == addUserBO.ID).FirstOrDefault <EO.User>() : null;

            if (addUserBO != null)
            {
                userDB.Password = PasswordHash.HashPassword(addUserBO.Password);
            }

            _context.SaveChanges();

            userDB = _context.Users.Where(p => p.ID == userDB.ID && p.IsDeleted.Value == false).FirstOrDefault <EO.User>();
            var res = userDB;

            return((object)res);
        }
Ejemplo n.º 2
0
        public override object ValidateInvitation <T>(T data)
        {
            BO.UserPasswordActivation invitationBO = (BO.UserPasswordActivation)(object) data;
            EO.UserPasswordActivation invitation   = _context.UserPasswordActivations.Where(p => p.PasswordActivattionKey == invitationBO.PasswordActivattionKey).FirstOrDefault <EO.UserPasswordActivation>();
            //p.IsExpired != true &&

            if (invitation != null)
            {
                invitation.IsExpired             = true;
                _context.Entry(invitation).State = System.Data.Entity.EntityState.Modified;
                _context.SaveChanges();
            }

            else
            {
                return(new BO.ErrorObject {
                    ErrorMessage = "Invalid appkey or other parameters.", errorObject = "", ErrorLevel = BO.ErrorLevel.Error
                });
            }
            return((object)(invitation));
        }
Ejemplo n.º 3
0
        public override Object Save <T>(T entity)
        {
            BO.User userBO = (BO.User)(object) entity;
            if (userBO == null)
            {
                return new BO.ErrorObject {
                           ErrorMessage = "User object can't be null", errorObject = "", ErrorLevel = BO.ErrorLevel.Error
                }
            }
            ;

            EO.User userDB = new EO.User();
            EO.UserPasswordActivation activationDB = new EO.UserPasswordActivation();
            bool isEditMode = false;

            userDB.UserName      = userBO.UserName;
            userDB.FirstName     = userBO.FirstName;
            userDB.LastName      = userBO.LastName;
            userDB.ID            = userBO.ID;
            userDB.Password      = userBO.Password;
            userDB.CreatedBy     = userBO.CreatedBy;
            userDB.CreatedDate   = userBO.CreatedDate;
            userDB.UpdatedBy     = userBO.UpdatedBy;
            userDB.UpdatedDate   = userBO.UpdatedDate;
            userDB.IsDeleted     = userBO.IsDeleted;
            userDB.ImageUrl      = userBO.ImageUrl;
            userDB.ContactNumber = userBO.ContactNumber;
            if (userDB.ID > 0)
            {
                //UPDATE
            }
            else
            {
                //  if (_context.Users.Any(o => o.UserName == userBO.UserName && o.IsDeleted.Value == false))   return new BO.ErrorObject { ErrorMessage = "User already exists.", errorObject = "", ErrorLevel = BO.ErrorLevel.Information };
                userDB.CreatedDate = DateTime.UtcNow;

                _context.Users.Add(userDB);
            }
            _context.SaveChanges();

            #region Insert UserPasswordActivations

            activationDB.PasswordActivattionKey = Guid.NewGuid();
            activationDB.DateCreated            = userDB.CreatedDate;
            activationDB.UserID     = userDB.ID;
            activationDB.IsExpired  = false;
            activationDB.ExpiryDate = System.DateTime.Now.AddDays(1);
            _context.UserPasswordActivations.Add(activationDB);
            _context.SaveChanges();
            #endregion

            #region mail notification
            try
            {
                string VerificationLink = "<a href='" + Utility.GetConfigValue("VerificationLink") + "/" + activationDB.PasswordActivattionKey + "' target='_blank'>" + Utility.GetConfigValue("VerificationLink") + "/" + activationDB.PasswordActivattionKey + "</a>";

                string MailMessageForCompany = "Dear " + userDB.FirstName + ",<br><br>You have been registered in Our Portal. <br><br> Please confirm your account by clicking below link in order to use.<br><br><b>" + VerificationLink + "</b><br><br>Thanks";
                //  string NotificationForCompany = "You have been registered in midas portal as a Medical Provider. ";
                //  string SmsMessageForCompany = "Dear " + user.FirstName + ",<br><br>You have been registered in midas portal as a Medical provider. <br><br> Please confirm your account by clicking below link in order to use.<br><br><b>" + VerificationLink + "</b><br><br>Thanks";

                // NotificationHelper nh = new NotificationHelper();
                MessagingHelper mh = new MessagingHelper();

                #region  company mail object
                EmailMessage emCompany = new EmailMessage();
                emCompany.ApplicationName = "Civil Works";
                emCompany.ToEmail         = userDB.UserName;
                emCompany.EMailSubject    = "Civil Works Notification";
                emCompany.EMailBody       = MailMessageForCompany;
                #endregion

                //  mh.SendEmailAndSms(user_.UserName, 1,emCompany);

                mh.SendMail(userDB.UserName, emCompany.EMailSubject, MailMessageForCompany);
            }
            catch (Exception ex)
            {
            }
            #endregion
            return((object)userDB);
        }