Beispiel #1
0
 public ActionResult Create(CompanyModel model)
 {
     using (ExploreDbContext dbContext = new ExploreDbContext())
     {
         dbContext.Company.Add(model);
         dbContext.SaveChanges();
     }
     return(View("Index"));
 }
Beispiel #2
0
        public ActionResult AddCompanyReview(CompanyViewModel companyModel)
        {
            try
            {
                //Get the Database Context
                ExploreDbContext dbContext = new ExploreDbContext();

                // Create Company
                CompanyModel newCompany = new CompanyModel()
                {
                    companyname = companyModel.CompanyName,
                    location = companyModel.Lat + "," + companyModel.Long,
                    overallrating = companyModel.rating, id = Guid.NewGuid().ToString()
                };

                newCompany =  dbContext.Company.Add(newCompany);

                // Create Job Position
                PositionModel newPosition = new PositionModel()
                {
                    id = Guid.NewGuid().ToString(),companyid = newCompany.id,
                    overallrating = companyModel.rating, positionname = companyModel.PositionName
                };

                newPosition = dbContext.AddPositionModel(newPosition);

                //Create Job Review
                ReviewModel newReview = new ReviewModel()
                {
                    id = Guid.NewGuid().ToString(), createddate = DateTime.Now,dislikes = 0, likes=0,
                    reviewmessage = companyModel.review, overallrating = companyModel.rating,UserId = User.Identity.GetUserId(),
                    PositionId = newPosition.id,totalreview = 1
                };

                newReview = dbContext.AddReviewModel(newReview);

                dbContext.SaveChanges();

            }
            catch (Exception ex)
            {
                //Suppress Exception           
            }
  

            return RedirectToActionPermanent("Index");
        }
Beispiel #3
0
 public ActionResult Edit(CompanyModel model)
 {
     using (ExploreDbContext dbContext = new ExploreDbContext())
     {
         CompanyModel editModel = dbContext.Company.Where(x => x.id == model.id).FirstOrDefault();
         if (editModel != null)
         {
             editModel.description = model.description;
             editModel.companyname = model.companyname;
             editModel.address     = model.address;
             editModel.location    = model.location;
             editModel.logourl     = model.logourl;
             editModel.website     = model.website;
             dbContext.SaveChanges();
         }
     }
     return(RedirectToAction("Index"));
 }
Beispiel #4
0
        public void OnInsertOfPositionRecord(PositionModel model)
        {
            try
            {
                // Update the Companies Rating based on the Position Rating
                if (model == null)
                {
                    return;
                }
                IEnumerable <PositionModel> positionList = _dbContext.Position.Where(x => x.companyid == model.companyid);
                int calculatedRating = Convert.ToInt32((positionList.Average(x => x.overallrating) + model.overallrating) / 2);

                // Get the Company Record
                CompanyModel companyModel = _dbContext.Company.Where(comp => comp.id == model.companyid).FirstOrDefault();
                if (companyModel != null)
                {
                    companyModel.overallrating = calculatedRating;
                    _dbContext.SaveChanges();
                }
            }
            catch (Exception ex)
            {
            }
        }