Esempio n. 1
0
        public Article Create(Article entity)
        {
            var create = _Context.Articles.Add(entity);

            _Context.SaveChanges();
            return(create.Entity);
        }
        public async Task <IActionResult> JobCategory(UserJobCategoryViewModal category)
        {
            category.UserJobCatList.ForEach(val =>
            {
                var user = _profileDbContext.UserJobCategory.ToList().Find(v => v.JobCategoryId == val.CatId);
                if (val.IsUserCategory)
                {
                    if (user == null)
                    {
                        _profileDbContext.UserJobCategory.Add(new Models.Profile.UserJobCategory
                        {
                            UserId        = category.UserId,
                            JobCategoryId = val.CatId
                        });
                    }
                }
                else
                {
                    if (user != null)
                    {
                        var toDelete = _profileDbContext.UserJobCategory.Where(v => v.JobCategoryId == val.CatId).FirstOrDefault();
                        if (toDelete != null)
                        {
                            _profileDbContext.UserJobCategory.Remove(toDelete);
                        }
                    }
                }
            });

            _profileDbContext.SaveChanges();
            return(await Task.Run(() => View(category)));
        }
Esempio n. 3
0
        public IActionResult Create(Profile model)
        {
            model.TimeCreated = DateTime.Now;

            _db.Profiles.Add(model);
            _db.SaveChanges();
            return(RedirectToAction(nameof(Index)));
        }
        //Metod för att byta profilbild
        public ActionResult ChangePicture(HttpPostedFileBase File)
        {
            //Vi kollar att det finns en bild att spara
            if (File != null && File.ContentLength > 0)
            {
                //Hämtar filnamnet utan filändelse
                var NoExtension = Path.GetFileNameWithoutExtension(File.FileName);
                //Hämtar filändelsen
                var Extension = Path.GetExtension(File.FileName);
                //Lägger ihop de båda, men med nuvarande tidpukt i namnet.
                //Det görs för att filnamnet ska bli unikt.
                var NameOfFile = NoExtension + DateTime.Now.ToString("yyyy-MM-dd-fff") + Extension;
                //Filen där bilderna sparas och filnamnet slås ihop till en sträng
                var    NameOfPath = "/Images/" + NameOfFile;
                string FilePath   = Path.Combine(Server.MapPath("~/Images/"), NameOfFile);
                //Bilden sparas
                File.SaveAs(FilePath);

                var pdb            = new ProfileDbContext();
                var userId         = User.Identity.GetUserId();
                var currentProfile =
                    pdb.Profiles.FirstOrDefault(p => p.UserID == userId);
                //Bildens sökväg sparas i databasen
                currentProfile.ProfileURL = NameOfPath;
                pdb.SaveChanges();

                return(RedirectToAction("ShowProfile", "Profile", new { showID = userId }));
            }
            else
            {
                return(RedirectToAction("Error", "Profile"));
            }
        }
Esempio n. 5
0
 public static void Initialize(ProfileDbContext context)
 {
     if (!context.LanguageLevels.Any())
     {
         context.LanguageLevels.AddRange(
             new LanguageLevel
         {
             LevelName = "A1 Elementary"
         },
             new LanguageLevel
         {
             LevelName = "A2 Pre-Intermediate"
         },
             new LanguageLevel
         {
             LevelName = "B1 Intermediate"
         },
             new LanguageLevel
         {
             LevelName = "B2 Upper-Intermediate"
         },
             new LanguageLevel
         {
             LevelName = "C1 Advanced"
         },
             new LanguageLevel
         {
             LevelName = "C2 Proficiency"
         }
             );
         context.SaveChanges();
     }
 }
        public void PushEntry(MessageModel model)
        {
            model.SendDate = DateTimeOffset.Now;
            var ctx = new ProfileDbContext();

            ctx.Messages.Add(model);
            ctx.SaveChanges();
        }
        public static void EnsureSeedData(this ProfileDbContext profileDbContext)
        {
            if (profileDbContext == null)
            {
                throw new ArgumentNullException(nameof(profileDbContext));
            }

            AddIdProviders(profileDbContext);
            profileDbContext.SaveChanges();
        }
Esempio n. 8
0
        // Ta bort skickade vänförfrågningar.
        public ActionResult RemoveRequest(int removeID)
        {
            // Använder inkommande ID på vänförfrågan för att ta bort denna.
            var ctx    = new ProfileDbContext();
            var remove = ctx.FriendRequestModels.FirstOrDefault(f => f.Id == removeID);

            ctx.FriendRequestModels.Remove(remove);
            ctx.SaveChanges();
            // Skickar vidare en till ens skickade vänförfrågningar.
            return(RedirectToAction("OutgoingList"));
        }
Esempio n. 9
0
        //Metod för att ta bort person ur vänlista
        public ActionResult RemoveFriend(string friendID)
        {
            var ctx       = new ProfileDbContext();
            var currentID = User.Identity.GetUserId();
            var remove    = ctx.Friends.FirstOrDefault(f => f.Person1 == friendID && f.Person2 == currentID || f.Person1 == currentID && f.Person2 == friendID);

            ctx.Friends.Remove(remove);
            ctx.SaveChanges();

            return(RedirectToAction("FriendList"));
        }
Esempio n. 10
0
        public ActionResult RequestList(string friendID)
        {
            var ctx       = new ProfileDbContext();
            var currentID = User.Identity.GetUserId();
            // Kontrollerar att ID inte är tomt och att den användaren existerar.
            var friendExist = ctx.Profiles.Any(p => p.UserID == friendID);

            if ((!(friendID == null)) && friendExist)
            {
                // Kontrollerar om det inte finns vänförfrågningar sen innan.
                if (!(ctx.FriendRequestModels.Any(f =>
                                                  (f.Person1 == currentID && f.Person2 == friendID) ||
                                                  (f.Person1 == friendID && f.Person2 == currentID)
                                                  )))
                {
                    // Kontrollerar att användarna inte är vänner sen innan.
                    if (!(ctx.Friends.Any(f =>
                                          (f.Person1 == currentID && f.Person2 == friendID) ||
                                          (f.Person1 == friendID && f.Person2 == currentID))))
                    {
                        // Vid lyckat resultat, skapas en FriendRequestModel och läggs in i databasen.
                        ctx.FriendRequestModels.Add(new FriendRequestModels
                        {
                            Person1 = currentID,
                            Person2 = friendID
                        });
                        ctx.SaveChanges();
                        return(View(new RequestSent {
                            Success = true
                        }));
                    }
                    else
                    {
                        return(View(new RequestSent {
                            Success = false, Error = "Already friends"
                        }));
                    }
                }
                else
                {
                    return(View(new RequestSent {
                        Success = false, Error = "Request is already sent"
                    }));
                }
            }
            else
            {
                return(View(new RequestSent {
                    Success = false, Error = "Something went wrong, please try again"
                }));
            }
        }
Esempio n. 11
0
        // Hanterar den respons användaren gör på vänförfrågan.
        public ActionResult RequestRespone(int requestID, bool acceptRequest)
        {
            var ctx           = new ProfileDbContext();
            var friendRequest = ctx.FriendRequestModels.FirstOrDefault(f => f.Id == requestID);

            // Vid accapterande av vänförfrågan.
            if (acceptRequest)
            {
                var addFriend = new FriendModel {
                    Person1 = friendRequest.Person1, Person2 = friendRequest.Person2
                };
                ctx.Friends.Add(addFriend);
                ctx.SaveChanges();
            }
            // Sen tas den bort, vilket sker i båda fallen (accept/decline).
            var remove = ctx.FriendRequestModels.FirstOrDefault(f => f.Id == requestID);

            ctx.FriendRequestModels.Remove(remove);
            ctx.SaveChanges();
            // Skickas tillbaka till inkommande förfrågningar.
            return(RedirectToAction("IncommingList"));
        }
Esempio n. 12
0
        public ActionResult EditProfile(ProfileViewModel p)
        {
            var ctx     = new ProfileDbContext();
            var userId  = User.Identity.GetUserId();
            var profile = ctx.Profiles.FirstOrDefault(pr => pr.UserId == userId);

            profile.Location     = p.Profile.Location;
            profile.Occupation   = p.Profile.Occupation;
            profile.Presentation = p.Profile.Presentation;
            ctx.SaveChanges();

            return(RedirectToAction("ViewProfile"));
        }
Esempio n. 13
0
        public void CreateResumeForStudent(int studentId)
        {
            Resume resume = new Resume
            {
                StudentId = studentId,
                Status    = ResumeStatuses.New
            };

            _db.Resume.Add(resume);

            //we have to call SaveChange explicitly because we need to retrieve id further in ResumeController
            _db.SaveChanges();
        }
Esempio n. 14
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email
                };

                var profileCtx = new ProfileDbContext();
                profileCtx.Profiles.Add(new Profile()
                {
                    UserId    = user.Id,
                    BirthDate = model.BirthDate,
                    FirstName = model.FirstName,
                    LastName  = model.LastName
                });

                var ImgCtx = new ImageDbContext();
                //Ger användaren en default bild vid skapandet av nytt konto
                ImgCtx.Images.Add(new Image()
                {
                    UserID    = user.Id,
                    Title     = "Default",
                    ImagePath = "~/Image/Default.jpg",
                    ImageFile = null
                });



                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    ImgCtx.SaveChanges();
                    profileCtx.SaveChanges();
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    return(RedirectToAction("Index", "Home"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Esempio n. 15
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    // Here is the default values. Keep in mind, changing these will effect the program.
                    var dFirstName   = "Firstname";
                    var dLastName    = "Lastname";
                    var dDescription = "Description";
                    var dLocation    = "Location";
                    var dURL         = "/Images/default_profile.png";
                    // ------------------------ //
                    using (var dbContext = new ProfileDbContext())
                    {
                        dbContext.Profiles.Add(new Profile()
                        {
                            UserID      = user.Id,
                            BirthDate   = DateTime.Now,
                            Description = dDescription,
                            FirstName   = dFirstName,
                            LastName    = dLastName,
                            Location    = dLocation,
                            ProfileURL  = dURL
                        });
                        dbContext.SaveChanges();
                    }

                    // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    return(RedirectToAction("Index", "Profile" /*, new { id = user.Id } */));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Esempio n. 16
0
        public static void Seed(ProfileDbContext dbContext)
        {
            if (dbContext.Profiles.Any())
            {
                return;
            }

            dbContext.Profiles.Add(new Profile()
            {
                UserId  = "*****@*****.**",
                Alias   = "ALFKI",
                Loyalty = Loyalty.Platnum
            });

            dbContext.SaveChanges();
        }
Esempio n. 17
0
        public static void Initialize(ProfileDbContext context)
        {
            if (!context.EducationLevels.Any())
            {
                context.EducationLevels.AddRange(
                    new EducationLevel
                {
                    Level = "Higher"
                },
                    new EducationLevel
                {
                    Level = "Bachelor"
                },
                    new EducationLevel
                {
                    Level = "Master"
                },
                    new EducationLevel
                {
                    Level = "Candidate of science"
                },
                    new EducationLevel
                {
                    Level = "Doctor of science"
                },
                    new EducationLevel
                {
                    Level = "Incomplete higher"
                },
                    new EducationLevel
                {
                    Level = "Vocational secondary",
                },
                    new EducationLevel
                {
                    Level = "Secondary",
                },
                    new EducationLevel
                {
                    Level = "another",
                }
                    );

                context.SaveChanges();
            }
        }
Esempio n. 18
0
        public bool UpdateUserProfileData([FromBody] ProfileDto profile)
        {
            if (ModelState.IsValid)
            {
                using (var context = new ProfileDbContext())
                {
                    var userInDb    = context.Users.Single(u => u.Email == profile.Email);
                    var profileInDb = context.Profiles.Single(p => p.UserId == userInDb.Id);

                    profileInDb.FirstName = profile.FirstName;
                    profileInDb.LastName  = profile.LastName;
                    profileInDb.Street    = profile.Street;
                    profileInDb.City      = profile.City;
                    profileInDb.State     = profile.State;

                    if (context.SaveChanges() > 0)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
        public ActionResult Update(ProfileViewModels model)
        {
            //Vi kontrollerar att födelsedatumet ligger inom spannet 1900 till i år.
            if (model.BirthDate.Year < 1900 || model.BirthDate.Year > DateTime.Now.Year)
            {
                ModelState.AddModelError("BirthDate", "Date not valid");
                return(View(model));
            }
            var profileContext = new ProfileDbContext();
            var userId         = User.Identity.GetUserId();
            var currentProfile =
                profileContext.Profiles.FirstOrDefault(p => p.UserID == userId);

            currentProfile.FirstName   = model.FirstName;
            currentProfile.LastName    = model.LastName;
            currentProfile.BirthDate   = model.BirthDate;
            currentProfile.Description = model.Description;
            currentProfile.Location    = model.Location;

            profileContext.SaveChanges();

            return(RedirectToAction("ShowProfile", "Profile", new { showID = userId }));
        }
Esempio n. 20
0
 protected void Insert(TEntity entity)
 {
     _table.Add(entity);
     _dataContext.SaveChanges();
 }
Esempio n. 21
0
        public static void Initialize(ProfileDbContext context)
        {
            IList <Stream> streams = new List <Stream>
            {
                new Stream
                {
                    StreamFullName  = "Android Developer",
                    StreamShortName = "AD"
                },
                new Stream
                {
                    StreamFullName  = "Java Automated Testing",
                    StreamShortName = "AT"
                },
                new Stream
                {
                    StreamFullName  = "Business Analyst",
                    StreamShortName = "BA"
                },
                new Stream
                {
                    StreamFullName  = "C++ Developer",
                    StreamShortName = "CD"
                },
                new Stream
                {
                    StreamFullName  = "Front-end",
                    StreamShortName = "FD"
                },
                new Stream
                {
                    StreamFullName  = "Java Developer",
                    StreamShortName = "JD"
                },
                new Stream
                {
                    StreamFullName  = "ASP.NET Developer",
                    StreamShortName = "ND"
                },
                new Stream
                {
                    StreamFullName  = "iOS Developer",
                    StreamShortName = "ID"
                },
                new Stream
                {
                    StreamFullName  = "PHP Developer",
                    StreamShortName = "PD"
                },
                new Stream
                {
                    StreamFullName  = "Python Developer",
                    StreamShortName = "PT"
                },
                new Stream
                {
                    StreamFullName  = "Python Automated Testing",
                    StreamShortName = "PT2"
                },
                new Stream
                {
                    StreamFullName  = "Software Testing",
                    StreamShortName = "ST"
                },
                new Stream
                {
                    StreamFullName  = "UI/UX Designer",
                    StreamShortName = "UI/UX"
                }
            };

            foreach (Stream str in streams)
            {
                var existingStream = context.Streams.FirstOrDefault(s => s.StreamShortName == str.StreamShortName);
                if (existingStream != null)
                {
                    existingStream.StreamFullName  = str.StreamFullName;
                    existingStream.StreamShortName = str.StreamShortName;
                    context.Streams.Update(existingStream);
                }
                else
                {
                    context.Streams.Add(str);
                }
            }

            context.SaveChanges();
        }
Esempio n. 22
0
        public static void Initialize(ProfileDbContext context)
        {
            IList <Skill> skills = new List <Skill> {
                #region Default skills
                new Skill
                {
                    Name = "Java Core"
                },
                new Skill
                {
                    Name = "Android SDK"
                },
                new Skill
                {
                    Name = "RxJava"
                },
                new Skill
                {
                    Name = "RxAndroid"
                },
                new Skill
                {
                    Name = "Java"
                },
                new Skill
                {
                    Name = "Selenium Webdriver"
                },
                new Skill
                {
                    Name = "XML"
                },
                new Skill
                {
                    Name = "HTML"
                },
                new Skill
                {
                    Name = "CSS"
                },
                new Skill
                {
                    Name = "Analyzing Requirements"
                },
                new Skill
                {
                    Name = "Vision&Scope"
                },
                new Skill
                {
                    Name = "BPMN"
                },
                new Skill
                {
                    Name = "С++"
                },
                new Skill
                {
                    Name = "Qt Framework"
                },
                new Skill
                {
                    Name = "STL"
                },
                new Skill
                {
                    Name = "Servlets"
                },
                new Skill
                {
                    Name = "Spring"
                },
                new Skill
                {
                    Name = "С#"
                },
                new Skill
                {
                    Name = "ASP.NET MVC"
                },
                new Skill
                {
                    Name = "SOLID"
                },
                new Skill
                {
                    Name = "Swift"
                },
                new Skill
                {
                    Name = "Xcode"
                },
                new Skill
                {
                    Name = "PHP"
                },
                new Skill
                {
                    Name = "Symfony"
                },
                new Skill
                {
                    Name = "MySQL"
                },
                new Skill
                {
                    Name = "Python"
                },
                new Skill
                {
                    Name = "Django"
                },
                new Skill
                {
                    Name = "UnitTest"
                },
                new Skill
                {
                    Name = "Linux"
                },
                new Skill
                {
                    Name = "Automation"
                },
                new Skill
                {
                    Name = "Functional testing"
                },
                new Skill
                {
                    Name = "TestRail"
                },
                new Skill
                {
                    Name = "Jira"
                },
                new Skill
                {
                    Name = "Adobe Photoshop"
                },
                new Skill
                {
                    Name = "Adobe Illustrator"
                },
                new Skill
                {
                    Name = "Axure"
                },
                #endregion

                #region Recommended skills
                new Skill
                {
                    Name = "Android API"
                },
                new Skill
                {
                    Name = "REST"
                },
                new Skill
                {
                    Name = "Retrofit"
                },
                new Skill
                {
                    Name = "Android studio"
                },
                new Skill
                {
                    Name = "ButterKnife"
                },
                new Skill
                {
                    Name = "SQLite"
                },
                new Skill
                {
                    Name = "Social Network"
                },
                new Skill
                {
                    Name = "C++"
                },
                new Skill
                {
                    Name = "Git"
                },
                new Skill
                {
                    Name = "Confluence"
                },
                new Skill
                {
                    Name = "Scrum"
                },
                new Skill
                {
                    Name = "Agile"
                },
                new Skill
                {
                    Name = "Software Development Methodologies"
                },
                new Skill
                {
                    Name = "Software Development Processes"
                },
                new Skill
                {
                    Name = "English"
                },
                new Skill
                {
                    Name = "Jenkins"
                },
                new Skill
                {
                    Name = "Testlink"
                },
                new Skill
                {
                    Name = "SOAP UI"
                },
                new Skill
                {
                    Name = "Test Plan"
                },
                new Skill
                {
                    Name = "Test case"
                },
                new Skill
                {
                    Name = "Manual testing"
                },
                new Skill
                {
                    Name = "Regression testing"
                },
                new Skill
                {
                    Name = "UML"
                },
                new Skill
                {
                    Name = "User story"
                },
                new Skill
                {
                    Name = "Prototyping"
                },
                new Skill
                {
                    Name = "Diagramming"
                },
                new Skill
                {
                    Name = "Modelling Tools"
                },
                new Skill
                {
                    Name = "Presentation techniques"
                },
                new Skill
                {
                    Name = "Software requirements specification"
                },
                new Skill
                {
                    Name = "Boost"
                },
                new Skill
                {
                    Name = "JavaScript"
                },
                new Skill
                {
                    Name = "Design patterns"
                },
                new Skill
                {
                    Name = "MultiThread programming"
                },
                new Skill
                {
                    Name = "OOP"
                },
                new Skill
                {
                    Name = "Bootstrap"
                },
                new Skill
                {
                    Name = "Webpack"
                },
                new Skill
                {
                    Name = "Angular"
                },
                new Skill
                {
                    Name = "SASS"
                },
                new Skill
                {
                    Name = "LESS"
                },
                new Skill
                {
                    Name = "ReactJS"
                },
                new Skill
                {
                    Name = "JSON"
                },
                new Skill
                {
                    Name = "Babel"
                },
                new Skill
                {
                    Name = "SDLC"
                },
                new Skill
                {
                    Name = "Hibernate"
                },
                new Skill
                {
                    Name = "JSP"
                },
                new Skill
                {
                    Name = "JBoss"
                },
                new Skill
                {
                    Name = "Web Services"
                },
                new Skill
                {
                    Name = "SQL"
                },
                new Skill
                {
                    Name = "REST API"
                },
                new Skill
                {
                    Name = "JQuery"
                },
                new Skill
                {
                    Name = "Entity Framework"
                },
                new Skill
                {
                    Name = "MS SQL"
                },
                new Skill
                {
                    Name = "NoSQL"
                },
                new Skill
                {
                    Name = "iOS"
                },
                new Skill
                {
                    Name = "Objective-C"
                },
                new Skill
                {
                    Name = "Cocoa Touch"
                },
                new Skill
                {
                    Name = "Core Data"
                },
                new Skill
                {
                    Name = "MVC"
                },
                new Skill
                {
                    Name = "Redis"
                },
                new Skill
                {
                    Name = "Drupal"
                },
                new Skill
                {
                    Name = "Flask"
                },
                new Skill
                {
                    Name = "Tornado"
                },
                new Skill
                {
                    Name = "RabbitMQ"
                },
                new Skill
                {
                    Name = "Robot framework"
                },
                new Skill
                {
                    Name = "Nginx"
                },
                new Skill
                {
                    Name = "PostgreSQL"
                },
                new Skill
                {
                    Name = "АPI testing"
                },
                new Skill
                {
                    Name = "Black Box testing"
                },
                new Skill
                {
                    Name = "GUI testing"
                },
                new Skill
                {
                    Name = "Test strategy development"
                },
                new Skill
                {
                    Name = "Requirements Testing"
                },
                new Skill
                {
                    Name = "Sketch"
                },
                new Skill
                {
                    Name = "CorelDRAW"
                },
                new Skill
                {
                    Name = "UI"
                },
                new Skill
                {
                    Name = "UX"
                },
                new Skill
                {
                    Name = "Responsive design"
                },
                new Skill
                {
                    Name = "Mobile design"
                },
                new Skill
                {
                    Name = "Web design"
                },
                new Skill
                {
                    Name = "Usability"
                }

                #endregion
            };

            foreach (Skill skill in skills)
            {
                var existingSkill = context.Skills.FirstOrDefault(s => s.Name == skill.Name);
                if (existingSkill == null)
                {
                    context.Skills.Add(skill);
                }
            }

            context.SaveChanges();
        }
Esempio n. 23
0
 public void Create(T entity)
 {
     _entities.Add(entity);
     _context.SaveChanges();
 }
Esempio n. 24
0
 public IActionResult Create(Models.User model)
 {
     _db.Users.Add(model);
     _db.SaveChanges();
     return(RedirectToAction(nameof(Index)));
 }
Esempio n. 25
0
        public async Task <IActionResult> ImportTrainerAccounts(ImportAccountsViewModel viewModel)
        {
            //Keep track of added users
            //Use this vars to minimize database quering
            Dictionary <String, String> generatedPasswords = new Dictionary <string, string>();
            List <ApplicationUser>      usersToNotify      = new List <ApplicationUser>();
            List <UserInfo>             userInfosToNotify  = new List <UserInfo>();

            string spreadsheetId = "";

            try
            {
                //break the link and extrach the id
                spreadsheetId = viewModel.ApiKey.Split(new[] { '/' })[5];
            }
            catch
            {
                ModelState.AddModelError("WrongLink", "There was an issue processing your request. Please verify the link you are pasting are from a google spreadsheet.");
                await PopulateViewModel(viewModel);

                return(View("ImportAccounts", viewModel));
            }

            //get the api key
            ApplicationUser loggedUser = await GetUserAsync();

            //Define the web request params
            string sheetRange = "A2:Z";
            string apiKey     = _userInfoService.GetUserInfo(loggedUser?.Email).GoogleApiKey;
            string requestUrl = "https://sheets.googleapis.com/v4/spreadsheets/" + spreadsheetId + "/values/" + sheetRange + "?key=" + apiKey;

            //create request
            HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(requestUrl);

            using (HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse())
            {
                //read the response stream
                StreamReader reader     = new StreamReader(webResponse.GetResponseStream());
                var          jsonString = reader.ReadToEnd();

                //parse the response stream
                JObject deserealizedJson       = JsonConvert.DeserializeObject(jsonString) as JObject;
                IEnumerable <JToken> tableRows = deserealizedJson.GetSheetRow(2);

                //check if the spreadsheet contains duplicate emails
                List <string> ssEmails = new List <string>();
                foreach (JToken row in tableRows)
                {
                    ssEmails.Add(row.GetElementValue(2));
                }
                if (ssEmails.Count != ssEmails.Distinct().Count())
                {
                    ModelState.AddModelError("DuplicateEmails", "It seems that the Google table contains duplicate emails. Please check the table and try again.");
                    await PopulateViewModel(viewModel);

                    return(View("ImportAccounts", viewModel));
                }

                //get teh list of current trainers' emails in the database
                IList <string> databaseTrainerEmails = _trainerService.GetTrainerEmailsByRoleName(ProfilerRoles.Trainer);

                //check if a email is already present in the system
                foreach (JToken row in tableRows)
                {
                    string sheetRowEmail = row.GetElementValue(2);

                    if (!databaseTrainerEmails.Contains(sheetRowEmail))
                    {
                        //pick values from the spreadsheet for the new user
                        ApplicationUser user = new ApplicationUser()
                        {
                            UserName = sheetRowEmail, Email = sheetRowEmail
                        };

                        //generate a password
                        string password = PasswordGenerator.Generate(6, 0);

                        var result = await _userManager.CreateAsync(user, password);

                        if (result.Succeeded)
                        {
                            //add to the dictionary (for testing only)
                            generatedPasswords.Add(user.UserName, password);

                            //add to the role Trainers
                            var currentUser = await _userManager.FindByNameAsync(user.UserName);

                            await _userManager.AddToRoleAsync(currentUser, ProfilerRoles.Trainer);

                            //add user info
                            //TODO: parse the number
                            UserInfo userInfo = new UserInfo
                            {
                                UserId    = currentUser.Id,
                                EnName    = row.GetElementValue(0),
                                EnSurname = row.GetElementValue(1),
                                Email     = row.GetElementValue(2),
                                Phone     = row.GetElementValue(3)
                            };

                            await _userInfoService.AddUserInfoAsync(userInfo);

                            //bind userInfo to applicationUser
                            currentUser.UserInfo = userInfo;

                            //keep track of the new email
                            usersToNotify.Add(currentUser);
                            userInfosToNotify.Add(userInfo);
                        }
                    }
                }

                try
                {
                    //save changes to the database
                    _db.SaveChanges();
                }
                catch
                {
                    ModelState.AddModelError("Import failed", "Server error: can’t create new accounts. Please try again later.");
                    await PopulateViewModel(viewModel);

                    return(View("ImportAccounts", viewModel));
                }
            }

            ////send emails
            //foreach (ApplicationUser userToNotify in usersToNotify)
            //{
            //    UserInfo thisUserInfo = userInfosToNotify.FirstOrDefault(x => x.UserId == userToNotify.Id);
            //    string userPassword = generatedPasswords.FirstOrDefault(x => x.Key == userToNotify.Email).Value;
            //    string appLink = _configuration.GetSection("ProfileAppLink").Value;

            //    EmailSender emailSender = new EmailSender();
            //    StringBuilder sb = new StringBuilder();
            //    sb.AppendLine("Здравствуйте, " + thisUserInfo.RuName + " " + thisUserInfo.RuSurname + ".");
            //    sb.AppendLine("");
            //    sb.AppendLine("Для вас была создана учетная запись в системе PROFILE.");
            //    //sb.AppendLine("Please use this link: " + appLink + " and this password: "******" to log in to your account.");
            //    sb.AppendLine("Для входа в систему используйте ваш пароль - " + userPassword);
            //    await emailSender.SendEmailAsync(userToNotify.Email, "Данные вашей учетной записи в Системе PROFILE Образовательного центра ПВТ", sb.ToString());
            //}

            return(View("ImportAccountsResult", generatedPasswords));
        }
Esempio n. 26
0
 public static void Initialize(ProfileDbContext context)
 {
     if (!context.Languages.Any())
     {
         context.Languages.AddRange(
             new Language
         {
             Name = "English"
         },
             new Language
         {
             Name = "Afrikaans"
         },
             new Language
         {
             Name = "Albanian"
         },
             new Language
         {
             Name = "Arabic"
         },
             new Language
         {
             Name = "Armenian"
         },
             new Language
         {
             Name = "Belarusian"
         },
             new Language
         {
             Name = "Bulgarian"
         },
             new Language
         {
             Name = "Chinese"
         },
             new Language
         {
             Name = "Croatian"
         },
             new Language
         {
             Name = "Czech"
         },
             new Language
         {
             Name = "Danish"
         },
             new Language
         {
             Name = "Dutch"
         },
             new Language
         {
             Name = "Estonian"
         },
             new Language
         {
             Name = "Finnish"
         },
             new Language
         {
             Name = "French"
         },
             new Language
         {
             Name = "Georgian"
         },
             new Language
         {
             Name = "German"
         },
             new Language
         {
             Name = "Greek"
         },
             new Language
         {
             Name = "Hebrew"
         },
             new Language
         {
             Name = "Hindi"
         },
             new Language
         {
             Name = "Hungarian"
         },
             new Language
         {
             Name = "Icelandic"
         },
             new Language
         {
             Name = "Indonesian"
         },
             new Language
         {
             Name = "Irish"
         },
             new Language
         {
             Name = "Italian"
         },
             new Language
         {
             Name = "Japanese"
         },
             new Language
         {
             Name = "Korean"
         },
             new Language
         {
             Name = "Latvian"
         },
             new Language
         {
             Name = "Lithuanian"
         },
             new Language
         {
             Name = "Macedonian"
         },
             new Language
         {
             Name = "Norwegian"
         },
             new Language
         {
             Name = "Persian"
         },
             new Language
         {
             Name = "Polish"
         },
             new Language
         {
             Name = "Portuguese"
         },
             new Language
         {
             Name = "Romanian"
         },
             new Language
         {
             Name = "Russian"
         },
             new Language
         {
             Name = "Serbian"
         },
             new Language
         {
             Name = "Slovak"
         },
             new Language
         {
             Name = "Slovenian"
         },
             new Language
         {
             Name = "Spanish"
         },
             new Language
         {
             Name = "Swedish"
         },
             new Language
         {
             Name = "Turkish"
         },
             new Language
         {
             Name = "Ukrainian"
         },
             new Language
         {
             Name = "Urdu"
         },
             new Language
         {
             Name = "Uzbek"
         },
             new Language
         {
             Name = "Vietnamese"
         }
             );
         context.SaveChanges();
     }
 }
Esempio n. 27
0
        public static void Initialize(ProfileDbContext context)
        {
            if (!context.StreamSkills.Any())
            {
                context.StreamSkills.AddRange(

                    #region Skills for Android Developer (AD)

                    new StreamSkill
                {
                    Stream = context.Streams.FirstOrDefault(s => s.StreamShortName == "AD"),
                    Skill  = context.Skills.FirstOrDefault(sk => sk.Name == "Java Core")
                },
                    new StreamSkill
                {
                    Stream = context.Streams.FirstOrDefault(s => s.StreamShortName == "AD"),
                    Skill  = context.Skills.FirstOrDefault(sk => sk.Name == "Android SDK")
                },
                    new StreamSkill
                {
                    Stream = context.Streams.FirstOrDefault(s => s.StreamShortName == "AD"),
                    Skill  = context.Skills.FirstOrDefault(sk => sk.Name == "RxJava")
                },
                    new StreamSkill
                {
                    Stream = context.Streams.FirstOrDefault(s => s.StreamShortName == "AD"),
                    Skill  = context.Skills.FirstOrDefault(sk => sk.Name == "RxAndroid")
                },

                    #endregion

                    #region Skills for Java Automated Testing (AT)

                    new StreamSkill
                {
                    Stream = context.Streams.FirstOrDefault(s => s.StreamShortName == "AT"),
                    Skill  = context.Skills.FirstOrDefault(sk => sk.Name == "Java")
                },
                    new StreamSkill
                {
                    Stream = context.Streams.FirstOrDefault(s => s.StreamShortName == "AT"),
                    Skill  = context.Skills.FirstOrDefault(sk => sk.Name == "Selenium Webdriver")
                },
                    new StreamSkill
                {
                    Stream = context.Streams.FirstOrDefault(s => s.StreamShortName == "AT"),
                    Skill  = context.Skills.FirstOrDefault(sk => sk.Name == "XML")
                },
                    new StreamSkill
                {
                    Stream = context.Streams.FirstOrDefault(s => s.StreamShortName == "AT"),
                    Skill  = context.Skills.FirstOrDefault(sk => sk.Name == "HTML")
                },
                    new StreamSkill
                {
                    Stream = context.Streams.FirstOrDefault(s => s.StreamShortName == "AT"),
                    Skill  = context.Skills.FirstOrDefault(sk => sk.Name == "CSS")
                },

                    #endregion

                    #region Skills for Business Analyst (BA)

                    new StreamSkill
                {
                    Stream = context.Streams.FirstOrDefault(s => s.StreamShortName == "BA"),
                    Skill  = context.Skills.FirstOrDefault(sk => sk.Name == "Analyzing Requirements")
                },
                    new StreamSkill
                {
                    Stream = context.Streams.FirstOrDefault(s => s.StreamShortName == "BA"),
                    Skill  = context.Skills.FirstOrDefault(sk => sk.Name == "Vision&Scope")
                },
                    new StreamSkill
                {
                    Stream = context.Streams.FirstOrDefault(s => s.StreamShortName == "BA"),
                    Skill  = context.Skills.FirstOrDefault(sk => sk.Name == "BPMN")
                },

                    #endregion

                    #region Skills for C++ Developer (CD)

                    new StreamSkill
                {
                    Stream = context.Streams.FirstOrDefault(s => s.StreamShortName == "CD"),
                    Skill  = context.Skills.FirstOrDefault(sk => sk.Name == "С++")
                },
                    new StreamSkill
                {
                    Stream = context.Streams.FirstOrDefault(s => s.StreamShortName == "CD"),
                    Skill  = context.Skills.FirstOrDefault(sk => sk.Name == "Qt Framework")
                },
                    new StreamSkill
                {
                    Stream = context.Streams.FirstOrDefault(s => s.StreamShortName == "CD"),
                    Skill  = context.Skills.FirstOrDefault(sk => sk.Name == "STL")
                },

                    #endregion

                    #region Skills for Front-end Developer (FD)

                    new StreamSkill
                {
                    Stream = context.Streams.FirstOrDefault(s => s.StreamShortName == "FD"),
                    Skill  = context.Skills.FirstOrDefault(sk => sk.Name == "HTML")
                },
                    new StreamSkill
                {
                    Stream = context.Streams.FirstOrDefault(s => s.StreamShortName == "FD"),
                    Skill  = context.Skills.FirstOrDefault(sk => sk.Name == "CSS")
                },
                    new StreamSkill
                {
                    Stream = context.Streams.FirstOrDefault(s => s.StreamShortName == "FD"),
                    Skill  = context.Skills.FirstOrDefault(sk => sk.Name == "JavaScript")
                },
                    new StreamSkill
                {
                    Stream = context.Streams.FirstOrDefault(s => s.StreamShortName == "FD"),
                    Skill  = context.Skills.FirstOrDefault(sk => sk.Name == "jQuery")
                },

                    #endregion

                    #region Skills for Java Developer (JD)

                    new StreamSkill
                {
                    Stream = context.Streams.FirstOrDefault(s => s.StreamShortName == "JD"),
                    Skill  = context.Skills.FirstOrDefault(sk => sk.Name == "Java Core")
                },
                    new StreamSkill
                {
                    Stream = context.Streams.FirstOrDefault(s => s.StreamShortName == "JD"),
                    Skill  = context.Skills.FirstOrDefault(sk => sk.Name == "Servlets")
                },
                    new StreamSkill
                {
                    Stream = context.Streams.FirstOrDefault(s => s.StreamShortName == "JD"),
                    Skill  = context.Skills.FirstOrDefault(sk => sk.Name == "Spring")
                },

                    #endregion

                    #region Skills for ASP.NET Developer (ND)

                    new StreamSkill
                {
                    Stream = context.Streams.FirstOrDefault(s => s.StreamShortName == "ND"),
                    Skill  = context.Skills.FirstOrDefault(sk => sk.Name == "С#")
                },
                    new StreamSkill
                {
                    Stream = context.Streams.FirstOrDefault(s => s.StreamShortName == "ND"),
                    Skill  = context.Skills.FirstOrDefault(sk => sk.Name == "ASP.NET MVC")
                },
                    new StreamSkill
                {
                    Stream = context.Streams.FirstOrDefault(s => s.StreamShortName == "ND"),
                    Skill  = context.Skills.FirstOrDefault(sk => sk.Name == "SOLID")
                },

                    #endregion

                    #region Skills for IOS Developer (ID)

                    new StreamSkill
                {
                    Stream = context.Streams.FirstOrDefault(s => s.StreamShortName == "ID"),
                    Skill  = context.Skills.FirstOrDefault(sk => sk.Name == "Swift")
                },
                    new StreamSkill
                {
                    Stream = context.Streams.FirstOrDefault(s => s.StreamShortName == "ID"),
                    Skill  = context.Skills.FirstOrDefault(sk => sk.Name == "Xcode")
                },
                    new StreamSkill
                {
                    Stream = context.Streams.FirstOrDefault(s => s.StreamShortName == "ID"),
                    Skill  = context.Skills.FirstOrDefault(sk => sk.Name == "SOLID")
                },

                    #endregion

                    #region Skills for PHP Developer (PD)

                    new StreamSkill
                {
                    Stream = context.Streams.FirstOrDefault(s => s.StreamShortName == "PD"),
                    Skill  = context.Skills.FirstOrDefault(sk => sk.Name == "PHP")
                },
                    new StreamSkill
                {
                    Stream = context.Streams.FirstOrDefault(s => s.StreamShortName == "PD"),
                    Skill  = context.Skills.FirstOrDefault(sk => sk.Name == "Symfony")
                },
                    new StreamSkill
                {
                    Stream = context.Streams.FirstOrDefault(s => s.StreamShortName == "PD"),
                    Skill  = context.Skills.FirstOrDefault(sk => sk.Name == "MySQL")
                },

                    #endregion

                    #region Skills for Python Developer (PT)

                    new StreamSkill
                {
                    Stream = context.Streams.FirstOrDefault(s => s.StreamShortName == "PT"),
                    Skill  = context.Skills.FirstOrDefault(sk => sk.Name == "Python")
                },
                    new StreamSkill
                {
                    Stream = context.Streams.FirstOrDefault(s => s.StreamShortName == "PT"),
                    Skill  = context.Skills.FirstOrDefault(sk => sk.Name == "Django")
                },
                    new StreamSkill
                {
                    Stream = context.Streams.FirstOrDefault(s => s.StreamShortName == "PT"),
                    Skill  = context.Skills.FirstOrDefault(sk => sk.Name == "UnitTest")
                },

                    #endregion

                    #region Skills for Python Automated Testing (PT2)

                    new StreamSkill
                {
                    Stream = context.Streams.FirstOrDefault(s => s.StreamShortName == "PT2"),
                    Skill  = context.Skills.FirstOrDefault(sk => sk.Name == "Python")
                },
                    new StreamSkill
                {
                    Stream = context.Streams.FirstOrDefault(s => s.StreamShortName == "PT2"),
                    Skill  = context.Skills.FirstOrDefault(sk => sk.Name == "Linux")
                },
                    new StreamSkill
                {
                    Stream = context.Streams.FirstOrDefault(s => s.StreamShortName == "PT2"),
                    Skill  = context.Skills.FirstOrDefault(sk => sk.Name == "Automation")
                },

                    #endregion

                    #region Skills for Software Testing (ST)

                    new StreamSkill
                {
                    Stream = context.Streams.FirstOrDefault(s => s.StreamShortName == "ST"),
                    Skill  = context.Skills.FirstOrDefault(sk => sk.Name == "Functional testing")
                },
                    new StreamSkill
                {
                    Stream = context.Streams.FirstOrDefault(s => s.StreamShortName == "ST"),
                    Skill  = context.Skills.FirstOrDefault(sk => sk.Name == "TestRail")
                },
                    new StreamSkill
                {
                    Stream = context.Streams.FirstOrDefault(s => s.StreamShortName == "ST"),
                    Skill  = context.Skills.FirstOrDefault(sk => sk.Name == "Jira")
                },

                    #endregion

                    #region Skills for UI/UX Designer (UI/UX)

                    new StreamSkill
                {
                    Stream = context.Streams.FirstOrDefault(s => s.StreamShortName == "UI/UX"),
                    Skill  = context.Skills.FirstOrDefault(sk => sk.Name == "Adobe Photoshop")
                },
                    new StreamSkill
                {
                    Stream = context.Streams.FirstOrDefault(s => s.StreamShortName == "UI/UX"),
                    Skill  = context.Skills.FirstOrDefault(sk => sk.Name == "Adobe Illustrator")
                },
                    new StreamSkill
                {
                    Stream = context.Streams.FirstOrDefault(s => s.StreamShortName == "UI/UX"),
                    Skill  = context.Skills.FirstOrDefault(sk => sk.Name == "Axure")
                }

                    #endregion

                    );

                context.SaveChanges();
            }
        }