예제 #1
0
        public ActionResult Input(SolutionModel model)
        {
            if (ModelState.IsValid)
            {
                Solution solution = null;
                try
                {
                    if (model.Id > 0)
                        solution = _solutionService.Find(model.Id);
                    else
                        solution = new Solution();

                    #region Set value for category entity
                    solution.Name = model.Name;
                    solution.Alias = model.Alias;
                    solution.Brief = model.Brief;
                    solution.Description = model.Description;
                    solution.IsActive = model.IsActive;
                    solution.IsFeature = model.IsFeature;
                    solution.DisplayOrder = model.DisplayOrder;
                    solution.Thumbnail = model.Thumbnail != null ? model.Thumbnail : "default.jpg";
                    solution.RootId = model.RootId;//
                    solution.EnableGallery = model.EnableGallery;
                    solution.OpenLink = model.OpenLink;
                    solution.Link = model.Link;
                    #endregion

                    #region Perform save data
                    if (model.Id <= 0)
                    {
                        using (TransactionScope scope = new TransactionScope())
                        {
                            _solutionService.Insert(solution);
                            _unitOfWork.SaveChanges();
                            scope.Complete();
                        }
                    }
                    else
                    {
                        using (TransactionScope scope = new TransactionScope())
                        {
                            _solutionService.Update(solution);
                            _unitOfWork.SaveChanges();
                            scope.Complete();
                        }
                    }

                    return Json(new { Status = ResultStatus.Success, Message = "Data were saved successfully!" });
                    #endregion
                }
                catch
                {
                    return Json(new { Status = ResultStatus.Fail, Message = StringTable.DataSaveUnsuccess });
                }
            }
            else
            {
                return Json(new { Status = ResultStatus.Fail, Message = StringTable.DataSaveSuccess });
            }
        }
예제 #2
0
        public ActionResult Input(int id = 0)
        {
            var solution = _solutionService.Find(id);

            if (solution == null)
            {
                solution = new Solution()
                {
                    DisplayOrder = 1000,
                    IsActive = true,
                    IsFeature = true,
                    EnableGallery = true
                };
            }
            var model = solution.ToModel();
            var solutions = GetListCategory();
            if (id > 0)
                solutions = solutions.Where(x => x.Value != id.ToString()).ToList();
            ViewData["ListSolution"] = solutions;

            return View(model);
        }