Ejemplo n.º 1
0
        public ActionResult DeleteConfirmed(int id)
        {
            SavedJob savedJob = db.SavedJobs.Find(id);

            db.SavedJobs.Remove(savedJob);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 2
0
        public ActionResult Create([Bind(Include = "CompanyName,CompanyLink,Address,City,State,ZipCode,Latitude,Longitude,CareerPage")] Company company)
        {
            if (ModelState.IsValid)
            {
                db.Companies.Add(company);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(company));
        }
Ejemplo n.º 3
0
        protected override void Seed(JobBoardMvcContext context)
        {
            // Your seed code here...
            if (context.Jobs.Any())
            {
                return;
            }
            else
            {
                var jobsJsonAll = GetEmbeddedResourceAsString("JobBoardMVC.App_Data.Amazon.json");

                JArray  jsonValJobs = JArray.Parse(jobsJsonAll) as JArray;
                dynamic jobsData    = jsonValJobs;
                foreach (dynamic job in jobsData)
                {
                    context.Jobs.Add(new Job
                    {
                        ApplicationLink    = job.ApplicationLink,
                        CompanyCompanyName = job.CompanyName,
                        DatePosted         = job.DatePosted,
                        Experience         = job.Experience,
                        Hours         = job.Hours,
                        JobID         = job.JobId,
                        JobTitle      = job.JobTitle,
                        LanguagesUsed = job.LanguagesUsed,
                        Location      = job.Location,
                        Salary        = job.Salary
                    });
                }
                // Make sure to have the context save changes so next section can query Job table
                context.SaveChanges();

                /* populate the Place DBSet with distinct (enumerable) Location values
                 * // this code should migrate for a regular db load from scrapes
                 * IQueryable<string> query = from j in context.Jobs
                 *                         orderby j.Location
                 *                         select j.Location;
                 * dynamic placeData = query.Distinct().ToList();
                 * foreach (dynamic place in placeData)
                 * {
                 *  // what was the last row in the Place table - throws an exception if more than one rowID item listed
                 *  var rowNumber = getLastRowID(context).SingleOrDefault();
                 *  // stage a new row for place table
                 *  var Loc = new Place { Location = place, ID = rowNumber + 1 };
                 *  // write the row unless we already have that Location
                 *  context.Places.AddOrUpdate(p => p.Location, Loc);
                 *  // Make sure to have the context save changes so the rowNumber will update next iteration
                 *  context.SaveChanges();
                 * }
                 */
                // call base in case this overide seed method doesn't apply
                base.Seed(context);
            } // end of else
        }     // end of Seed method
Ejemplo n.º 4
0
        public ActionResult Edit(string id, HttpPostedFileBase upload)
        {
            if (id == null)
            {
                return(HttpNotFound());
            }
            var companyToUpdate = db.Companies.Find(id);

            try
            {
                if (upload != null && upload.ContentLength > 0)
                {
                    var oldLogo = companyToUpdate.Files.Any(f => f.FileType == FileType.Logo);
                    if (oldLogo == true)
                    {
                        db.CompanyFiles.Remove(companyToUpdate.Files.First(f => f.FileType == FileType.Logo));
                    }
                    var logo = new CompanyFile
                    {
                        FileName    = System.IO.Path.GetFileName(upload.FileName),
                        FileType    = FileType.Logo,
                        ContentType = upload.ContentType,
                        CompanyName = companyToUpdate.CompanyName
                    };
                    using (var reader = new System.IO.BinaryReader(upload.InputStream))
                    {
                        logo.Content = reader.ReadBytes(upload.ContentLength);
                    }
                    companyToUpdate.Files = new List <CompanyFile> {
                        logo
                    };
                }
                if (ModelState.IsValid && TryUpdateModel(companyToUpdate, new string[] { "CompanyName", "CompanyLink", "Address", "City", "State", "ZipCode", "Latitude", "Longitude", "CareerPage", "CompanyType", "IndustryServed", "LanguagesUsed", "Files" }))
                {
                    try
                    {
                        db.SaveChanges();
                        return(RedirectToAction("Details", new { id = companyToUpdate.CompanyName }));
                    }
                    catch (DataException /*ex*/)
                    {
                        ModelState.AddModelError("", "Unable to save changes.");
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(View(companyToUpdate));
        }
Ejemplo n.º 5
0
 public ActionResult Create(IdentityRole Role)
 {
     context.Roles.Add(Role);
     context.SaveChanges();
     return(RedirectToAction("Index", "Roles"));
 }