public async Task <ActionResult> EditCompanyIntro(Company model) { var company = db.Companies.Where(c => c.CompanyEmail == User.Identity.Name).FirstOrDefault(); company.CompanyIntroduction = model.CompanyIntroduction; await db.SaveChangesAsync(); return(PartialView("_CompanyIntro", model)); }
public async Task <ActionResult> EditOrAddHomePageContent(HomePageContent homePageContent) { var aCopyOfDatabase = new Internship_Management_SystemEntities(); if (db.HomePageContents.Any(h => h.HomePageContentId == homePageContent.HomePageContentId)) { var thisHomePageContent = db.HomePageContents.Where(h => h.HomePageContentId == homePageContent.HomePageContentId).FirstOrDefault(); thisHomePageContent.Content = homePageContent.Content; thisHomePageContent.Title = homePageContent.Title; } else { db.HomePageContents.Add(homePageContent); } try { await db.SaveChangesAsync(); }catch (Exception e) { db = aCopyOfDatabase; } return(PartialView("_HomePageContents", new HomePageContentViewModel(db.HomePageContents.ToList()))); }
public async Task <ActionResult> RegisterCompany(RegisterCompanyViewModel model) { if (ModelState.IsValid) { Internship_Management_SystemEntities db = new Internship_Management_SystemEntities(); var user = new ApplicationUser { UserName = model.Email, Email = model.Email }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { await UserManager.AddToRoleAsync(user.Id, "company"); await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false); // For more information on how to enable account confirmation and password reset please visit http://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 UshnerManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"); RegisterCompanyViewModel newRegisteredCompany = (RegisterCompanyViewModel)model; Company newCompany = new Company(); newCompany.CompanyEmail = newRegisteredCompany.Email; newCompany.CompanyName = newRegisteredCompany.Name; newCompany.PersonInCharge = newRegisteredCompany.PersonInCharge; newCompany.ContactNumber = newRegisteredCompany.ContactNumber; newCompany.CompanyLocation = newRegisteredCompany.CompanyLocation; if (db.Companies.Count() != 0) { var newCompanyOrder = db.Companies.Count() + 1; newCompany.CompanyOrder = newCompanyOrder; } else { newCompany.CompanyOrder = 1; } db.Companies.Add(newCompany); await db.SaveChangesAsync(); return(Json(new { redirectUrl = Url.Action("Index", "Home"), isRedirect = true })); } AddErrors(result); } return(PartialView("_CompanyRegister", model)); }
public async Task <ActionResult> RegisterTeacher(RegisterViewModel model) { if (ModelState.IsValid) { Internship_Management_SystemEntities db = new Internship_Management_SystemEntities(); var user = new ApplicationUser { UserName = model.Email, Email = model.Email }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { await UserManager.AddToRoleAsync(user.Id, "teacher"); await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false); // For more information on how to enable account confirmation and password reset please visit http://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 UshnerManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"); Teacher newTeacher = new Teacher(); newTeacher.TeacherName = model.Name; newTeacher.TeacherEmail = model.Email; newTeacher.TeacherContactNumber = model.ContactNumber; db.Teachers.Add(newTeacher); await db.SaveChangesAsync(); return(Json(new { redirectUrl = Url.Action("Index", "Home"), isRedirect = true })); } AddErrors(result); } // If we got this far, something failed, redisplay form return(PartialView("_TeacherRegister", model)); }
public async Task <ActionResult> UploadStudentInfo(FormCollection formCollection) { var thisTeacher = getThisTeacher(); if (Request != null) { //Create a copy of db so if user submit any files with problem that mess up db, it can be reverted back. var aCopyOfDB = new Internship_Management_SystemEntities(); try { //If there are already records of classes and students that are related to this teacher, delete them and replace with our new file. db.Students.RemoveRange(thisTeacher.Students); db.Class_.RemoveRange(thisTeacher.Class_); db.Contract_.RemoveRange(thisTeacher.Contract_); db.InternshipTasks.RemoveRange(thisTeacher.InternshipTasks); HttpPostedFileBase file = Request.Files["UploadedFile"]; if ((file != null) && (file.ContentLength > 0) && !string.IsNullOrEmpty(file.FileName)) { string fileName = file.FileName; string fileContentType = file.ContentType; byte[] fileBytes = new byte[file.ContentLength]; var data = file.InputStream.Read(fileBytes, 0, Convert.ToInt32(file.ContentLength)); } using (var package = new ExcelPackage(file.InputStream)) { var currentSheet = package.Workbook.Worksheets; var workSheet = currentSheet.First(); var noOfCol = workSheet.Dimension.End.Column; var noOfRow = workSheet.Dimension.End.Row; Class_ class_ = new Class_(); for (int rowIterator = 2; ; rowIterator++) { if (workSheet.Cells[rowIterator, 1].Value != null) { //Calculate the number of students in this specific class. if (class_.Students.Count != 0) { class_.NumberOfStudents = class_.Students.Count; db.Class_.Add(class_); } class_ = new Class_(); class_.Teacher = thisTeacher; class_.TeacherEmail = thisTeacher.TeacherEmail; class_.ClassName = workSheet.Cells[rowIterator, 1].Value.ToString(); } try { Student student = new Student(); student.Class_ = class_; student.ClassName = class_.ClassName; student.StudentName = workSheet.Cells[rowIterator, 2].Value.ToString(); student.PhoneNumber = workSheet.Cells[rowIterator, 3].Value.ToString(); student.TeacherEmail = thisTeacher.TeacherEmail; student.Teacher = thisTeacher; db.Students.Add(student); } catch (NullReferenceException ex) { class_.NumberOfStudents = class_.Students.Count; break; } } } await db.SaveChangesAsync(); } catch (Exception e) { db = aCopyOfDB; ViewData["isSuccessful"] = false; return(View("ForTeacher", prepareViewModel())); } ViewData["isSuccessful"] = true; } return(View("ForTeacher", prepareViewModel())); }