public ActionResult CreateAnnouncement(Announcement announcementModel)
        {
            try
            {
                // Find Company which will create Annoncement
                // Todo : find ID of Authenticated User/Company
                string id      = HttpContext.User.Identity.GetUserId();
                var    creator = db.Companies.Where(c => c.CompanySecondID.Equals(id)).FirstOrDefault();
                // TODO: Add insert logic here to Create Announcement
                string currentDate     = DateTime.Now.ToString("dd/MM/yyyy");
                var    newAnnouncement = new Announcement
                {
                    Title           = announcementModel.Title,
                    Description     = announcementModel.Description,
                    PublicationDate = Convert.ToDateTime(currentDate),
                    Location        = announcementModel.Location,
                    LevelID         = announcementModel.LevelID,
                    CategoryID      = announcementModel.CategoryID,
                    CompanyID       = creator.CompanyID
                };
                db.Announcements.Add(newAnnouncement);
                db.SaveChanges();

                return(RedirectToAction("GetAllAnnouncementDoneBy", "Announcement", new { idUser = id }));
            }
            catch
            {
                return(View());
            }
        }
        // DELETE: Copmany
        public ActionResult DeleteCompany(int id)
        {
            var companyToDelete = dbContext.Companies.Find(id);

            dbContext.Companies.Remove(companyToDelete);
            dbContext.SaveChanges();

            return(RedirectToAction("ListCompanies"));
        }
Beispiel #3
0
        public JsonResult Apply(string idUser, int idAnnouncement)
        {
            try
            {
                // TODO: Add insert logic here

                // Search for the candidate that has the same Hash code as idUser param
                Candidate appliedCandidate = db.Candidates.Where(c => c.CandidateSecondID.Equals(idUser)).FirstOrDefault();

                // The returning JSON Object
                object result = null;

                // todo: check if Candidate is already applyed to job
                var check = db.Applications.Where(a => a.CandidateID.Equals(appliedCandidate.CandidateID) && a.AnnouncementID.Equals(idAnnouncement)).FirstOrDefault();
                if (check == null)
                {
                    Application newApp = new Application
                    {
                        AnnouncementID  = idAnnouncement,
                        CandidateID     = appliedCandidate.CandidateID,
                        ApplicationDate = DateTime.Now,
                    };
                    db.Applications.Add(newApp);
                    db.SaveChanges();

                    result = new
                    {
                        EnableSuccess = true,
                        SuccessTitle  = "Success",
                        SuccessMsg    = "Your application has been sent successfully!"
                    };
                }
                else
                {
                    result = new
                    {
                        EnableSuccess = false,
                        ErrorTitle    = "Warning",
                        ErrorMsg      = "You are already applayed for this Job!"
                    };
                }
                return(this.Json(result, JsonRequestBehavior.AllowGet));
            }
            catch
            {
                return(Json(new
                {
                    EnableSuccess = false,
                    ErrorTitle = "Warning",
                    ErrorMsg = "Something went wrong!"
                }, JsonRequestBehavior.AllowGet));
            }
        }
Beispiel #4
0
        public ActionResult Edit(CandidateEditProfileViewModel model) // Ealash CandidateSecondID tayji null men view?
        {
            if (ModelState.IsValid)
            {
                // Get the email of current candidate
                string userHashID       = User.Identity.GetUserId();
                var    currentCandidate = db.Candidates.Where(c => c.CandidateSecondID == userHashID).FirstOrDefault();
                // Update logic goes here
                var    folderPath       = Server.MapPath("~/Data/Candidate/" + currentCandidate.Email);
                byte[] imageData        = null;
                string fullPathInServer = "~/Data/Candidate/" + currentCandidate.Email + "/";

                // Save Cv In Server Side
                if (model.CvFileName != null)
                {
                    string cvFileName      = Path.GetFileNameWithoutExtension(model.CvFileName.FileName);
                    string cvFileExtension = Path.GetExtension(model.CvFileName.FileName);
                    string _cvFileName     = cvFileName + cvFileExtension;
                    model.Cv    = fullPathInServer + _cvFileName;
                    _cvFileName = Path.Combine(Server.MapPath(fullPathInServer), _cvFileName);
                    model.CvFileName.SaveAs(_cvFileName);
                }

                // Save Photo In Server Side
                if (model.PhotoFileName != null)
                {
                    string photoFileName      = Path.GetFileNameWithoutExtension(model.PhotoFileName.FileName);
                    string photoFileExtension = Path.GetExtension(model.PhotoFileName.FileName);
                    string _photoFileName     = photoFileName + photoFileExtension;
                    model.Photo    = fullPathInServer + _photoFileName;
                    _photoFileName = Path.Combine(Server.MapPath(fullPathInServer), _photoFileName);
                    model.PhotoFileName.SaveAs(_photoFileName);

                    // Todo: convert the user uploaded Photo as Byte Array before save to DB/ ApplicationDbContext => AspNetUserTable

                    if (Request.Files.Count > 0)
                    {
                        HttpPostedFileBase fileBase = Request.Files["PhotoFileName"];
                        using (var binary = new BinaryReader(fileBase.InputStream))
                        {
                            imageData = binary.ReadBytes(fileBase.ContentLength);
                        }
                    }
                }

                // Save Cover Letter In Server Side
                if (model.CoverLetterFileName != null)
                {
                    string coverLetterFileName      = Path.GetFileNameWithoutExtension(model.CoverLetterFileName.FileName);
                    string coverLetterFileExtension = Path.GetExtension(model.CoverLetterFileName.FileName);
                    string _coverLetterFileName     = coverLetterFileName + coverLetterFileExtension;
                    model.CoverLetter    = fullPathInServer + _coverLetterFileName;
                    _coverLetterFileName = Path.Combine(Server.MapPath(fullPathInServer), _coverLetterFileName);
                    model.CoverLetterFileName.SaveAs(_coverLetterFileName);
                }


                // Updating candidate info in the identity DbContext
                var updatedUser = appDb.Users.Where(u => u.Id.Equals(userHashID)).FirstOrDefault();

                updatedUser.FirstName = model.FirstName;
                updatedUser.LastName  = model.LastName;
                updatedUser.UserPhoto = imageData;
                appDb.SaveChanges();

                if (model.PhotoFileName != null)
                {
                    updatedUser.UserPhoto = imageData;
                }

                // Updating candidate info in our DB
                Candidate updatedCandidate = db.Candidates.Where(c => c.CandidateSecondID.Equals(userHashID)).FirstOrDefault();
                updatedCandidate.FirstName   = model.FirstName;
                updatedCandidate.LastName    = model.LastName;
                updatedCandidate.Address     = model.Address;
                updatedCandidate.Bio         = model.Bio;
                updatedCandidate.DateOfBirth = model.DateOfBirth;
                updatedCandidate.PhoneNumber = model.PhoneNumber;
                updatedCandidate.Photo       = model.Photo;
                updatedCandidate.Cv          = model.Cv;
                updatedCandidate.CoverLetter = model.CoverLetter;

                db.SaveChanges();


                return(RedirectToAction("Index", "Candidate", new { idUser = User.Identity.GetUserId() }));
            }
            return(View());
        }
        public async Task <ActionResult> Register(RegisterViewModelCandidate model)
        {
            if (ModelState.IsValid)
            {
                // Todo: Create a folder for each Candidate

                var folderPath = Server.MapPath("~/Data/Candidate/" + model.Email);
                // Chech if Folder is Exists
                byte[] imageData = null;
                if (!Directory.Exists(folderPath))
                {
                    // Create Folder
                    Directory.CreateDirectory(Server.MapPath("~/Data/Candidate/" + model.Email));
                    string fullPathInServer = "~/Data/Candidate/" + model.Email + "/";

                    // Save Cv In Server Side
                    if (model.CvFileName != null)
                    {
                        string cvFileName      = Path.GetFileNameWithoutExtension(model.CvFileName.FileName);
                        string cvFileExtension = Path.GetExtension(model.CvFileName.FileName);
                        string _cvFileName     = cvFileName + cvFileExtension;
                        model.CV    = fullPathInServer + _cvFileName;
                        _cvFileName = Path.Combine(Server.MapPath(fullPathInServer), _cvFileName);
                        model.CvFileName.SaveAs(_cvFileName);
                    }

                    // Save Photo In Server Side
                    if (model.PhotoFileName != null)
                    {
                        string photoFileName      = Path.GetFileNameWithoutExtension(model.PhotoFileName.FileName);
                        string photoFileExtension = Path.GetExtension(model.PhotoFileName.FileName);
                        string _photoFileName     = photoFileName + photoFileExtension;
                        model.Photo    = fullPathInServer + _photoFileName;
                        _photoFileName = Path.Combine(Server.MapPath(fullPathInServer), _photoFileName);
                        model.PhotoFileName.SaveAs(_photoFileName);

                        // Todo: convert the user uploaded Photo as Byte Array before save to DB/ ApplicationDbContext => AspNetUserTable

                        if (Request.Files.Count > 0)
                        {
                            HttpPostedFileBase fileBase = Request.Files["PhotoFileName"];
                            using (var binary = new BinaryReader(fileBase.InputStream))
                            {
                                imageData = binary.ReadBytes(fileBase.ContentLength);
                            }
                        }
                    }

                    // Save Cover Letter In Server Side
                    if (model.CoverLetterFileName != null)
                    {
                        string coverLetterFileName      = Path.GetFileNameWithoutExtension(model.CoverLetterFileName.FileName);
                        string coverLetterFileExtension = Path.GetExtension(model.CoverLetterFileName.FileName);
                        string _coverLetterFileName     = coverLetterFileName + coverLetterFileExtension;
                        model.CoverLetter    = fullPathInServer + _coverLetterFileName;
                        _coverLetterFileName = Path.Combine(Server.MapPath(fullPathInServer), _coverLetterFileName);
                        model.CoverLetterFileName.SaveAs(_coverLetterFileName);
                    }
                }


                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email, FirstName = model.FirstName, LastName = model.LastName
                };

                if (model.PhotoFileName != null)
                {
                    user.UserPhoto = imageData;
                }

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

                if (result.Succeeded)
                {
                    var res = await UserManager.AddToRoleAsync(user.Id, "candidate");

                    using (JobPostingDBEntities1 db = new JobPostingDBEntities1())
                    {
                        var newCandidate = new Candidate
                        {
                            CandidateSecondID = user.Id,
                            FirstName         = model.FirstName,
                            LastName          = model.LastName,
                            Address           = model.Adresse,
                            Bio         = model.Bio,
                            DateOfBirth = model.DateOfBirth,
                            Email       = model.Email,
                            PhoneNumber = model.PhoneNumber,
                            Password    = model.Password,
                            Photo       = model.Photo,
                            Cv          = model.CV,
                            CoverLetter = model.CoverLetter
                        };

                        //db.Entry<Candidate>().State = System.Data.Entity.EntityState.Added;

                        db.Candidates.Add(newCandidate);
                        db.SaveChanges();
                    }

                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);


                    // Pour plus d'informations sur l'activation de la confirmation de compte et de la réinitialisation de mot de passe, visitez https://go.microsoft.com/fwlink/?LinkID=320771
                    // Envoyer un message électronique avec ce lien
                    // 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, "Confirmez votre compte", "Confirmez votre compte en cliquant <a href=\"" + callbackUrl + "\">ici</a>");


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

            // Si nous sommes arrivés là, un échec s’est produit. Réafficher le formulaire
            return(View(model));
        }
Beispiel #6
0
        public ActionResult Edit(CompanyEditViewModel p_company)
        {
            try
            {
                // TODO: Add update logic here
                if (ModelState.IsValid)
                {
                    // Get the email of the current logged in company
                    var uniqueID = User.Identity.GetUserId();
                    var email    = db.Companies.FirstOrDefault(c => c.CompanySecondID == uniqueID).Email;

                    // The path of the current logged in company's folder
                    var folderPath = Server.MapPath("~/Data/Companies/" + email);

                    Byte[] logoData = null;

                    string fullPathInServer = "~/Data/Companies/" + email + "/";

                    // Get file info of the logo
                    if (p_company.LogoFileName != null)
                    {
                        string logoFileName      = Path.GetFileNameWithoutExtension(p_company.LogoFileName.FileName);
                        string logoFileExtension = Path.GetExtension(p_company.LogoFileName.FileName);
                        string _logoFileName     = logoFileName + logoFileExtension;
                        p_company.Logo = fullPathInServer + _logoFileName;
                        _logoFileName  = Path.Combine(Server.MapPath(fullPathInServer), _logoFileName);
                        p_company.LogoFileName.SaveAs(_logoFileName);



                        // Todo: convert the Company uploaded Photo as Byte Array before save to DB/ ApplicationDbContext => AspNetUserTable
                        if (Request.Files.Count > 0)
                        {
                            HttpPostedFileBase fileBase = Request.Files["LogoFileName"];
                            using (var binary = new BinaryReader(fileBase.InputStream))
                            {
                                logoData = binary.ReadBytes(fileBase.ContentLength);
                            }
                        }
                    }

                    // Updating candidate info in the identity DbContext
                    var updatedUser = appDb.Users.Where(u => u.Id.Equals(uniqueID)).FirstOrDefault();

                    updatedUser.FirstName = p_company.Name;
                    updatedUser.LastName  = p_company.Name;
                    if (p_company.LogoFileName != null)
                    {
                        updatedUser.UserPhoto = logoData;
                    }
                    appDb.SaveChanges();

                    // Updating candidate info in our DB
                    Company updatedCompany = db.Companies.Where(c => c.CompanySecondID.Equals(uniqueID)).FirstOrDefault();

                    updatedCompany.Name        = p_company.Name;
                    updatedCompany.City        = p_company.City;
                    updatedCompany.Address     = p_company.Address;
                    updatedCompany.Description = p_company.Description;
                    updatedCompany.Logo        = p_company.Logo;
                    updatedCompany.PhoneNumber = p_company.PhoneNumber;

                    db.SaveChanges();
                    return(RedirectToAction("Index", "Home", new { idUser = uniqueID }));
                }
                ViewBag.ErrorMessage = "Something went wrong!";
                return(View());
            }
            catch
            {
                return(View());
            }
        }