Exemplo n.º 1
0
        public int UpdateUser(CoreUser user)
        {
            User userRecord = db.Users.Where(p => p.Id == user.id).FirstOrDefault();

            if (userRecord != null)
            {
                userRecord.Name  = user.Name;
                userRecord.Email = user.Email;
                if (user.Password != null)
                {
                    userRecord.Password = user.Password;
                }
                if (user.UserName != null)
                {
                    userRecord.UserName = user.UserName;
                }
                userRecord.RoleId = user.RoleId;
                //userRecord.Roles = db.Roles.Where(p => p.Id == user.RoleId).ToList();
                db.SaveChanges();
                return(user.id);
            }
            else
            {
                return(0);
            }
        }
Exemplo n.º 2
0
        public CoreUser GetUserById(int id)
        {
            var userData = db.Users.Where(p => p.Id == id).FirstOrDefault();

            CoreUser coreUserMap = new CoreUser();

            coreUserMap.Email    = userData.Email;
            coreUserMap.Name     = userData.Name;
            coreUserMap.UserName = userData.UserName;
            coreUserMap.RoleId   = userData.RoleId;

            return(coreUserMap);
        }
Exemplo n.º 3
0
        public string CreateUser(CoreUser model)
        {
            try
            {
                var isEmailExist = db.Users.Where(p => p.Email == model.Email).FirstOrDefault();
                var result       = "";
                if (isEmailExist != null)
                {
                    result = @"{ 'Status': 'exist', 'UserId':'','RoleId':''}";
                    return(result);
                }
                User user = new User();

                user.Title             = model.Title;
                user.Name              = model.Name;
                user.Email             = model.Email;
                user.UserName          = model.UserName;
                user.Password          = model.Password;
                user.Telephone         = model.Telephone;
                user.MobileNumber      = model.MobileNumber;
                user.Country           = db.Countries.Where(c => c.Id == model.CountryIdQual).FirstOrDefault();
                user.Country1          = db.Countries.Where(c => c.Id == model.CountryIdResd).FirstOrDefault();
                user.QualfiedDate      = model.QualfiedDate;
                user.JobLocation       = db.Countries.Where(c => c.Id == model.JobLocation).Select(c => c.Id).FirstOrDefault();
                user.ExperienceIn1     = model.ExperienceIn1;
                user.ExperienceIn2     = model.ExperienceIn2;
                user.CreatedByUserId   = null;
                user.CreatedOnDatetime = DateTime.Now;
                user.UpdatedByUserId   = null;
                user.IsActive          = true;
                user.UpdatedOnDatetime = DateTime.Now;
                //user.IsActive = false;

                user.RoleId = 4;

                List <Speciality> _listSpeciality = new List <Speciality>();
                _listSpeciality.Add(db.Specialities.Where(c => c.Id == model.Speciality1).FirstOrDefault());
                _listSpeciality.Add(db.Specialities.Where(c => c.Id == model.Speciality2).FirstOrDefault());
                _listSpeciality.Add(db.Specialities.Where(c => c.Id == model.Speciality3).FirstOrDefault());

                user.Specialities = _listSpeciality;

                var path = "";

                if (model.File != null && model.File.ContentLength > 0)
                {
                    var filename = Guid.NewGuid() + Path.GetFileName(model.File.FileName);
                    path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory + "UserDocuments\\", filename);
                    var filetype = Path.GetExtension(model.File.FileName);

                    List <UserDocument> listUserDoc = new List <UserDocument>();

                    UserDocument userDoc = new UserDocument();
                    userDoc.Name        = filename;
                    userDoc.Path        = path;
                    userDoc.DocType     = filetype;
                    userDoc.CreatedDate = DateTime.Now;
                    userDoc.UpdatedDate = DateTime.Now;

                    listUserDoc.Add(userDoc);

                    user.UserDocuments = listUserDoc;
                }

                db.Users.Add(user);
                db.SaveChanges();
                if (model.File != null)
                {
                    model.File.SaveAs(path);
                }
                //generate token and save in database

                string possibles = "abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ0123456789";
                char[] code      = new char[4];
                Random rd        = new Random();

                for (int i = 0; i < 4; i++)
                {
                    code[i] = possibles[rd.Next(0, possibles.Length)];
                }

                string codeString = new string(code);

                VerificationToken token = new VerificationToken();
                token.Token             = codeString;
                token.UserId            = user.Id;
                token.GeneratedDateTime = DateTime.Now;

                //db.VerificationTokens.Add(token);
                //db.SaveChanges();
                HttpContext.Current.Session["UserEmailId"] = user.Email;
                result = @"{ 'Status': '200', 'UserId':'" + user.Id + "','RoleId':'" + user.RoleId + "'}";
                return(result);
                //send mail for verification
                //SendNotification notify = new SendNotification();

                //string mailSubject = "Account verification";

                //bool mailStatus = notify.SendMailAccountVerification(model.Email, model.Name, user.Id, codeString, mailSubject);

                //if (mailStatus)
                //{
                //    return "success";
                //}
                //else
                //{
                //    DeleteUser(user.Id);
                //    return "mail failed";
                //}
            }
            catch (Exception ex)
            {
                return(ex.Message.ToString());;
            }
        }