public static bool SaveVisitorInfo()
        {
            UKareEntities db            = new UKareEntities();
            string        CurrentUserIp = GetUser_IP();
            //HttpContext.Current.Request.UserHostAddress;

            SiteVisit vister = db.SiteVisits.Where(p => p.IPaddress == CurrentUserIp && EntityFunctions.TruncateTime(p.LastVisitedDate) == EntityFunctions.TruncateTime(DateTime.Now)).FirstOrDefault();

            if (vister != null)
            {
                vister.VisitCount      = vister.VisitCount + 1;
                vister.LastVisitedDate = DateTime.Now;
                db.SaveChanges();
            }
            else
            {
                vister                 = new SiteVisit();
                vister.IPaddress       = CurrentUserIp;
                vister.LastVisitedDate = DateTime.Now;
                vister.VisitCount      = 1;
                db.SiteVisits.Add(vister);
                db.SaveChanges();
            }

            CurrentUserIp = string.Empty;
            vister        = null;
            db.Dispose();
            return(true);
        }
        public int SaveMessage(CoreMessage message)
        {
            try
            {
                Message messages = new Message();
                messages.Description   = message.Description;
                messages.Title         = message.Title;
                messages.MessageTypeId = 4;
                messages.MessageFor    = message.MessageFor;
                messages.CreatedDate   = DateTime.Now;
                messages.CreatedBy     = 6; //admin user id

                db.Messages.Add(messages);
                db.SaveChanges();

                return(messages.Id);
            }
            catch (DbEntityValidationException ex)
            {
                throw;
            }
        }
Exemple #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());;
            }
        }