public ActionResult ChangePassword(ChangePasswordViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            using (var context = new GvGenEntities())
            {
                var entity = context.TUsers.FirstOrDefault(m => m.Email == HttpContext.User.Identity.Name && m.Password == model.OldPassword);
                if (entity != null)
                {
                    entity.Password             = model.Password;
                    context.Entry(entity).State = System.Data.Entity.EntityState.Modified;
                    context.SaveChanges();
                    ViewBag.SuccessMessage = "Your password has been changed successfully! Thank you.";
                }
                else
                {
                    ModelState.AddModelError("OldPassword", "Current password incorrect.");
                    return(View(model));
                }
            }
            return(View());
        }
 public ActionResult Register(Register model)
 {
     if (!ModelState.IsValid)
     {
         return(View(model));
     }
     using (var context = new GvGenEntities())
     {
         var mailExists = context.TUsers.FirstOrDefault(m => m.Email == model.Email);
         if (mailExists == null)
         {
             var entity = new TUser();
             entity.Name     = model.Email;
             entity.Email    = model.Email;
             entity.Password = model.Password;
             entity.Role     = (int)AuthRole.User;
             context.TUsers.Add(entity);
             context.SaveChanges();
             return(RedirectToAction("ConfirmEmail"));
         }
         else
         {
             ModelState.AddModelError("Email", "Your email has been existed in the system.");
             return(View(model));
         }
     }
 }
        public HttpResponseMessage SubmitPersonalInfo([FromBody] Profile profile)
        {
            var entity = profile.GetNew();

            var token = Request.Headers.Authorization;

            if (token != null && token.Scheme.Length != 0 && token.Scheme != "null")
            {
                var id     = System.Web.Security.FormsAuthentication.Decrypt(token.Scheme).UserData.Split('|')[0];
                var userId = Convert.ToInt32(id);
                entity.IdUser = userId;
            }

            using (var db = new GvGenEntities())
            {
                if (entity.Id > 0)
                {
                    var entityEntry = db.Entry <TProfile>(entity);
                    entityEntry.State = EntityState.Modified;
                }
                else
                {
                    db.TProfiles.Add(entity);
                }

                db.SaveChanges();
            }
            var dataReturn = new { Id = entity.Id, GuidId = entity.IdProfile };
            var message    = Request.CreateResponse(HttpStatusCode.OK, dataReturn);

            return(message);
        }
        public HttpResponseMessage GetUserProfile(string idProfile)
        {
            using (var db = new GvGenEntities())
            {
                var profile = db.TProfiles.FirstOrDefault(e => e.IdProfile == new Guid(idProfile));
                if (profile == null)
                {
                    throw new Exception("Invalid Profile ID.");
                }

                var educations = db.TEducations.Where(ed => ed.IdProfile == profile.Id).ToList();
                var workExps   = db.TWorkExperiences.Where(w => w.IdProfile == profile.Id).ToList();
                var skills     = db.TSkills.Where(s => s.IdProfile == profile.Id).ToList();
                var references = db.TReferences.Where(r => r.IdProfile == profile.Id).ToList();

                var dataReturn = new
                {
                    PersonalInformation = profile,
                    Educations          = educations,
                    WorkExps            = workExps,
                    Skills     = skills,
                    References = references,
                };

                return(Request.CreateResponse(HttpStatusCode.OK, dataReturn));
            }
        }
        // GET: Resume
        public ActionResult ViewUserProfile(string idTemplate, string idProfile)
        {
            ResumeViewModel vm = new ResumeViewModel();

            using (var db = new GvGenEntities())
            {
                var template = db.TTemplates.FirstOrDefault(p => p.Name == idTemplate);

                if (template == null)
                {
                    //TODO:Redirect 404
                }

                var profile = db.TProfiles.FirstOrDefault(p => p.IdProfile == new Guid(idProfile));
                if (profile == null)
                {
                    //TODO:Redirect 404
                }
                else
                {
                    vm.Template            = template;
                    vm.PersonalInformation = profile;
                    vm.Educations          = db.TEducations.Where(ed => ed.IdProfile == profile.Id).ToList();
                    vm.WorkExps            = db.TWorkExperiences.Where(w => w.IdProfile == profile.Id).ToList();
                    vm.Skills     = db.TSkills.Where(s => s.IdProfile == profile.Id).ToList();
                    vm.References = db.TReferences.Where(r => r.IdProfile == profile.Id).ToList();
                }
            }

            return(View(vm));
        }
 public List <TEducation> GetEdus(int idProfile)
 {
     using (var db = new GvGenEntities())
     {
         var lst = db.TEducations.Where(e => e.IdProfile == idProfile).ToList();
         return(lst);
     }
 }
 public List <TSkill> GetSkills(int idProfile)
 {
     using (var db = new GvGenEntities())
     {
         var lst = db.TSkills.Where(e => e.IdProfile == idProfile).ToList();
         return(lst);
     }
 }
Exemple #8
0
 public List <TWorkExperience> GetWorkExps(int idProfile)
 {
     using (var db = new GvGenEntities())
     {
         var lst = db.TWorkExperiences.Where(e => e.IdProfile == idProfile).ToList();
         return(lst);
     }
 }
 public List <TTemplate> GetAll()
 {
     using (var db = new GvGenEntities())
     {
         var lst = db.TTemplates.ToList();
         return(lst);
     }
 }
        public HttpResponseMessage SubmitProfile([FromBody] Profile profile)
        {
            using (var db = new GvGenEntities())
            {
                var entity = profile.GetNew();

                db.TProfiles.Add(entity);
                db.SaveChanges();
            }

            return(new HttpResponseMessage(HttpStatusCode.OK));
        }
        protected bool UpdateConvertibleModelList <T, K>(int parentId, List <T> lst) where T : IConvertibleModel <K> where K : IEntity
        {
            var newItems     = GetNewItems(lst);
            var existedItems = GetExistedItems(lst);

            using (var context = new GvGenEntities())
            {
                var set = context.Set(typeof(K));
                // create new skills
                if (newItems != null)
                {
                    foreach (var item in newItems)
                    {
                        set.Add(item.GetEntity());
                    }
                }

                // update existing skills
                if (existedItems != null && existedItems.Any())
                {
                    var currentItems = GetListDb(parentId, set).ToList();
                    //var currentItems = set.ToListAsync().Result;
                    foreach (var item in existedItems)
                    {
                        var entity = currentItems.FirstOrDefault(s => (s as IEntity).Id == item.Id);
                        if (entity == null)
                        {
                            return(false);
                        }

                        item.Update((K)entity);
                        set.Attach(entity);
                        DbEntityEntry entry = context.Entry(entity);
                        entry.State = EntityState.Modified;
                    }

                    foreach (var entity in currentItems.ToList())
                    {
                        var foundSkill = existedItems.FirstOrDefault(s => s.Id == (entity as IEntity).Id);
                        if (foundSkill == null)
                        {
                            set.Attach(entity);
                            DbEntityEntry entry = context.Entry(entity);
                            entry.State = EntityState.Deleted;
                        }
                    }
                }

                context.SaveChanges();

                return(true);
            }
        }
        public ActionResult ViewMyCvs()
        {
            var            userEmail = HttpContext.User.Identity.Name;
            MyCvsViewModel viewModel = new MyCvsViewModel();

            viewModel.UserEmail = userEmail;

            using (var db = new GvGenEntities())
            {
                var userId = db.TUsers.First(u => u.Email == userEmail).Id;
                var user   = db.TUsers.First(u => u.Email == userEmail);
                viewModel.PersonalInformations = db.TProfiles.Where(p => p.IdUser == userId).ToList();
            }

            return(View(viewModel));
        }
        public bool RegisterUser(Login model)
        {
            using (var context = new GvGenEntities())
            {
                var mailExists = context.TUsers.First(m => m.Email == model.Email);
                if (mailExists == null)
                {
                    var entity = new TUser();
                    entity.Name     = model.Email;
                    entity.Email    = model.Email;
                    entity.Password = model.Password;
                    entity.Role     = (int)AuthRole.User;
                    context.TUsers.Add(entity);

                    return(true);
                }

                return(false);
            }
        }