Ejemplo n.º 1
0
        public IActionResult Edit(EventCategoryViewModels model)
        {
            if (ModelState.IsValid)
            {
                var m = _dbContext.EventCategories
                        .Where(i => i.Id == model.Id)
                        .FirstOrDefault();

                if (m != null)
                {
                    m.Name        = model.Name;
                    m.Description = model.Description;
                    m.Image       = model.Image;
                }
                else
                {
                    m         = model.Adapt <EventCategory>();
                    m.Created = User.Identity.Name;
                    _dbContext.EventCategories.Add(m);
                }

                _dbContext.SaveChanges();
                this.AddToastMessage("Success", "Event category saved successfully", ToastType.Success);
            }
            else
            {
                this.AddToastMessage("Warning", "Somthing went wrong, please try again ", ToastType.Warning);
            }
            IEnumerable <EventCategory> list = _dbContext.EventCategories.ToList();

            return(View("Index", list));
        }
Ejemplo n.º 2
0
        public IActionResult Edit(int id)
        {
            EventCategoryViewModels model = null;

            try
            {
                model = _dbContext.EventCategories
                        .Where(i => i.Id == id)
                        .FirstOrDefault()
                        .Adapt <EventCategoryViewModels>();
            }
            catch (Exception)
            {
                this.AddToastMessage("Error", "Somthing went wrong, please try again ", ToastType.Error);
            }
            this.AddToastMessage("Info", "Getting event category model for edit", ToastType.Info);

            return(View("Edit", model));
        }