Beispiel #1
0
        public ActionResult Edit([Bind(Include = "ID,Title,Company,StartDate,EndDate,link")] ExperiencesViewModel experiencesViewModel, IEnumerable <string> listSkillOfExperiencesId, IEnumerable <string> isSkillSelected)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var origineExperience = db.Experiences.Include(x => x.Skills).Where(x => x.ID == experiencesViewModel.ID).Single();
                    origineExperience.Title     = experiencesViewModel.Title;
                    origineExperience.Company   = experiencesViewModel.Company;
                    origineExperience.StartDate = experiencesViewModel.StartDate;
                    origineExperience.EndDate   = experiencesViewModel.EndDate;
                    origineExperience.link      = experiencesViewModel.link;

                    addOrUpdateSkillWithObjects(origineExperience, listSkillOfExperiencesId, isSkillSelected);

                    db.Entry(origineExperience).State = EntityState.Modified;
                    db.SaveChanges();
                }
                catch (DbEntityValidationException dbEx)
                {
                    Exception raise = dbEx;
                    foreach (var validationErrors in dbEx.EntityValidationErrors)
                    {
                        foreach (var validationError in validationErrors.ValidationErrors)
                        {
                            string message = string.Format("Property: {0} Error: {1}",
                                                           validationError.PropertyName,
                                                           validationError.ErrorMessage);
                            raise = new InvalidOperationException(message, raise);
                        }
                    }
                    ViewBag.ErrorMessage = raise.Message;
                    Log.write(raise.Message, "ERR");
                    return(View("Error"));
                }
                catch (Exception ex)
                {
                    Log.write(ex.Message, "ERR");
                    return(View("Error"));
                }
                return(RedirectToAction("Index"));
            }
            return(View(experiencesViewModel));
        }
        private ExperiencesViewModel CreateExperiences()
        {
            var list = new List <ExperienceViewModel>
            {
                new ExperienceViewModel
                {
                    ShortDescription = "1 Day Luxury package",
                    Price            = 95
                },
                new ExperienceViewModel
                {
                    ShortDescription = "3 Day VIP Dinning",
                    Price            = 150
                },
                new ExperienceViewModel
                {
                    ShortDescription = "1 Month total lounge",
                    Price            = 400
                },
                new ExperienceViewModel
                {
                    ShortDescription = "1 week access",
                    Price            = 295
                },
                new ExperienceViewModel
                {
                    ShortDescription = "1 month lounge access",
                    Price            = 495
                },
                new ExperienceViewModel
                {
                    ShortDescription = "1 year access",
                    Price            = 750
                }
            };
            var experiencesViewModel = new ExperiencesViewModel
            {
                Experiences = list
            };

            return(experiencesViewModel);
        }
Beispiel #3
0
        // GET: Experiences/Edit/5
        public ActionResult Edit(int?id)
        {
            ViewBag.ExperienceID = id;

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ExperiencesViewModel experiencesViewModel = db.Experiences.Find(id);

            experiencesViewModel.Skills = db.Skills.Include(p => p.Experiences).ToList();
            Utility.populateWithDescription(new List <ExperiencesViewModel> {
                experiencesViewModel
            }, "en", EPopulate.Experiences);
            if (experiencesViewModel == null)
            {
                return(HttpNotFound());
            }
            return(View(experiencesViewModel));
        }
Beispiel #4
0
        public ActionResult Create([Bind(Include = "ID,Title,Company,StartDate,EndDate,link")] ExperiencesViewModel experiencesViewModel, IEnumerable <string> listSkillOfExperiencesId, IEnumerable <string> isSkillSelected)
        {
            if (ModelState.IsValid)
            {
                addOrUpdateSkillWithObjects(experiencesViewModel, listSkillOfExperiencesId, isSkillSelected);

                try
                {
                    db.Experiences.Add(experiencesViewModel);
                    db.SaveChanges();
                }
                catch (Exception ex)
                {
                    Log.write(ex.Message, "ERR");
                }
                return(RedirectToAction("Index"));
            }

            return(View(experiencesViewModel));
        }
Beispiel #5
0
        private void addOrUpdateSkillWithObjects(ExperiencesViewModel experience, IEnumerable <string> listSkillOfExperiencesId, IEnumerable <string> isSkillSelected)
        {
            // Project Skills handling
            List <int> listAddedSkillsId = new List <int>();

            if (isSkillSelected != null)
            {
                int             id;
                SkillsViewModel newSkill;
                for (int i = 0; i < isSkillSelected.Count(); i++)
                {
                    string isSelected = isSkillSelected.ElementAt(i).Split('-').ToList()[0];
                    string selectedId = isSkillSelected.ElementAt(i).Split('-').ToList()[1];
                    id       = Int32.Parse(selectedId);
                    newSkill = db.Skills.Where(y => y.ID == id).Include("CategoryViewModel").Include("LevelsViewModel").Include(x => x.Projects).Include(x => x.Projects.Select(s => s.ProjectDetail)).Include(x => x.Experiences).DefaultIfEmpty().Single();
                    //var projectWithDetail = db.Projects.Where(p => p.Skills.Where(y => y.ID == newSkill.ID).Join(p.ProjectDetail)).Include(z=>z.);

                    if (isSelected == "true")
                    {
                        experience.Skills.Add(newSkill);
                        listAddedSkillsId.Add(id);
                    }
                }
            }

            // removing uncheck Projects skills
            if (listSkillOfExperiencesId != null)
            {
                foreach (var skillIdString in listSkillOfExperiencesId)
                {
                    var skillId = Int32.Parse(skillIdString);
                    if ((listAddedSkillsId != null && !listAddedSkillsId.Contains(skillId)) || listAddedSkillsId == null)
                    {
                        var skillToRemove = db.Skills.Where(x => x.ID == skillId).Include("CategoryViewModel").Include("LevelsViewModel").First();
                        experience.Skills.Remove(skillToRemove);
                    }
                }
            }
        }