Exemple #1
0
        public JsonResult Action(CategoryActionModel model)
        {
            var        result = false;
            JsonResult json   = new JsonResult();

            if (model.ID > 0) // We try to edit record
            {
                var category = CategoryService.Instance.GetCategoriesById(model.ID);
                category.Name        = model.Name;
                category.Description = model.Description;
                result = CategoryService.Instance.UpdateCategories(category);
            }
            else // We try to create record
            {
                Category category = new Category();
                category.Name        = model.Name;
                category.Description = model.Description;

                result = CategoryService.Instance.SaveCategories(category);
            }


            if (result)
            {
                json.Data = new { Success = true };
            }
            else
            {
                json.Data = new { Success = false, Message = "Unable to Perform action on Accomodation type" };
            }
            return(json);
        }
Exemple #2
0
        public ActionResult Delete(int ID)
        {
            CategoryActionModel model = new CategoryActionModel();
            var category = CategoryService.Instance.GetCategoriesById(ID);

            model.ID = category.ID;
            return(PartialView("_Delete", model));
        }
Exemple #3
0
        public async Task<JsonResult> Action(CategoryActionModel model)
        {
            JsonResult result = new JsonResult
            {
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            };
            var message = "";
            bool isSuccess = false;
            try
            {
                if (ModelState.IsValid)
                {
                    if (model.ID > 0)
                    {
                        _category = _ICategoryService.GetDataById(model.ID);
                        _category.Name = model.Name;
                        _category.Description = model.Description;
                        isSuccess = _ICategoryService.UpdateData(_category);
                    }
                    else
                    {
                        _category.Name = model.Name;
                        _category.Description = model.Description;
                        isSuccess = await Task.Run(() => _ICategoryService.SaveData(_category));
                    }
                }
                else
                {
                    message = string.Join("; ", ModelState.Values
                                           .SelectMany(x => x.Errors)
                                           .Select(x => x.ErrorMessage));
                }

            }
            catch (Exception ex)
            {
                message = ex.Message;
            }
            if (isSuccess)
            {
                message = "Data Save Successfully!!";
                result.Data = new { Success = true, Message = message };
            }
            else
            {
                result.Data = new { Success = false, Message = message };
            }
            return result;
        }
Exemple #4
0
        public ActionResult Action(int?ID)
        {
            CategoryActionModel model = new CategoryActionModel();

            if (ID.HasValue)//we are trying to edit record
            {
                var category = CategoryService.Instance.GetCategoriesById(ID.Value);
                model.ID          = category.ID;
                model.Name        = category.Name;
                model.Description = category.Description;
            }
            //else no need
            //{

            //}

            return(PartialView("_Action", model));
        }
Exemple #5
0
        public JsonResult Delete(CategoryActionModel model)
        {
            var        result = false;
            JsonResult json   = new JsonResult();

            var accomodatioType = CategoryService.Instance.GetCategoriesById(model.ID);

            result = CategoryService.Instance.DeleteCategories(accomodatioType);


            if (result)
            {
                json.Data = new { Success = true };
            }
            else
            {
                json.Data = new { Success = false, Message = "Unable to Perform action on Accomodation type" };
            }
            return(json);
        }