Пример #1
0
        public ActionResult Create(LifeInEsbjergViewModel model)
        {
            List<Category> allCat = new List<Category>(facade.GetCategoryGateway().ReadAll());
                for(int i = 0; i < allCat.Count; ++i)
                {
                    if(allCat.ElementAt(i).Id == model.selectedCat)
                    {
                        model.Company.Category = allCat.ElementAt(i);
                    }
                }

            facade.GetCompanyGateway().Add(model.Company);
            return RedirectToAction("Index", "Company");
        }
Пример #2
0
        public ActionResult Edit(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            Company company = facade.GetCompanyGateway().Find(id);

            int selectedCat = company.Category.Id;

            var selectedTags = new List<int>();
            foreach (var item in company.Tags)
            {
                selectedTags.Add(item.Id);
            }

            var model = new LifeInEsbjergViewModel()
            {
                Company = company,
                Category = new SelectList(facade.GetCategoryGateway().ReadAll(), "Id", "Name"),
                selectedCat = selectedCat,
                Tags = new MultiSelectList(facade.GetTagGateway().ReadAll(), "Id", "Name"),
                selectedTags = selectedTags,
                nrRate = company.NrRate

            };

            model.ratings = new List<Rating>();

            foreach (var item in company.Ratings)
            {
                model.ratings.Add(item);
            }

            if (company == null)
            {
                return HttpNotFound();
            }
            return View(model);
        }
Пример #3
0
        public ActionResult Create(LifeInEsbjergViewModel model)
        {
            List<Category> allCat = new List<Category>(facade.GetCategoryGateway().ReadAll());
                for(int i = 0; i < allCat.Count; ++i)
                {
                    if(allCat.ElementAt(i).Id == model.selectedCat)
                    {
                        model.Company.Category = allCat.ElementAt(i);
                    }
                }

            if (model.selectedTags != null)
            {
                var newList = new List<Tag>();
                List<Tag> allTag = new List<Tag>(facade.GetTagGateway().ReadAll());
                for(int i = 0; i < allTag.Count(); ++i)
                {
                    for (int j = 0; j < model.selectedTags.Count(); ++j)
                    {
                        if (allTag.ElementAt(i).Id == model.selectedTags.ElementAt(j))
                            newList.Add(new Tag() { Id = model.selectedTags.ElementAt(j) , Name = allTag.ElementAt(i).Name});
                    }
                }

                //foreach (int id in model.selectedTags)
                //{
                //    newList.Add(new Tag() { Id = id });
                //}
                model.Company.Tags = newList;
            }
            model.Company.Ratings = new List<Rating>();
            model.Company.Reviews = new List<Review>();
            model.Company.Badges = new List<Badge>();
            model.Company.NrRate = 0;
            model.Company.userName = model.userName;

            facade.GetCompanyGateway().Add(model.Company);

            return RedirectToAction("Login", "Account");
        }
Пример #4
0
 public ActionResult Create(string userName)
 {
     var model = new LifeInEsbjergViewModel() { Category = new SelectList(facade.GetCategoryGateway().ReadAll(), "Id", "Name"),
                                                 Tags = new MultiSelectList(facade.GetTagGateway().ReadAll(), "Id", "Name"),
                                                 userName = userName};
     return View(model);
 }
Пример #5
0
        public ActionResult Edit(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            Company company = facade.GetCompanyGateway().Find(id);

            int selectedCat = company.Category.Id;

            var model = new LifeInEsbjergViewModel()
            {
                Company = company,
                Category = new SelectList(facade.GetCategoryGateway().ReadAll(), "Id", "Name"),
                selectedCat = selectedCat
            };

            if (company == null)
            {
                return HttpNotFound();
            }
            return View(model);
        }