Пример #1
0
 //
 // GET: /Company/Add
 public ActionResult Add()
 {
     var viewModel = new CompanyViewModel() { CompanyId = 0 };
     //return View();
     return PartialView("_AddOrEdit", viewModel);
 }
Пример #2
0
        //
        // GET: /Company/Details/By ID
        public ActionResult Details(int id)
        {
            var errorViewModel = new ErrorViewModel();

            try
            {
                //var company = _companyRepository.GetById(id);
                var company = _companyRepository.GetAll().SingleOrDefault(x => x.CompanyId == id);
                if (company != null)
                {
                    var viewModel = new CompanyViewModel() { CompanyId = company.CompanyId, CompanyName = company.CompanyName, Address = company.Address };
                    return PartialView("_Details", viewModel);
                }

                errorViewModel = ExceptionHelper.ExceptionErrorMessageForNullObject();
            }
            catch (Exception ex)
            {
                errorViewModel = ExceptionHelper.ExceptionErrorMessageFormat(ex);
            }

            return PartialView("_ErrorPopup", errorViewModel);
        }
Пример #3
0
        public ActionResult Save(CompanyViewModel companyViewModel)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    //add
                    if (companyViewModel.CompanyId == 0 && companyViewModel.ActionName == "Add")
                    {
                        var model = new TblCompany() { CompanyId = companyViewModel.CompanyId + 1, CompanyName = companyViewModel.CompanyName, Address = companyViewModel.Address, CreatedBy = "Rasel", CreatedDate = DateTime.Now, UpdatedBy = "Rasel", UpdatedDate = DateTime.Now };

                        _companyRepository.Insert(model);
                    }
                    else if (companyViewModel.ActionName == "Edit") //edit
                    {
                        TblCompany company = _companyRepository.GetById(Convert.ToInt32(companyViewModel.CompanyId));

                        if (company != null)
                        {

                            company.CompanyId = companyViewModel.CompanyId;
                            company.CompanyName = companyViewModel.CompanyName;
                            company.Address = companyViewModel.Address;
                            company.UpdatedBy = "Rasel";
                            company.UpdatedDate = DateTime.Now;

                            _companyRepository.Update(company);

                        }
                        else
                        {
                            return Content(KendoUiHelper.GetKendoUiWindowAjaxSuccessMethod(Boolean.FalseString, companyViewModel.ActionName, MessageType.warning.ToString(), ExceptionHelper.ExceptionMessageForNullObject()));
                        }

                    }

                    _companyRepository.Save();

                    return Content(KendoUiHelper.GetKendoUiWindowAjaxSuccessMethod(Boolean.TrueString, companyViewModel.ActionName, MessageType.success.ToString(), "Saved Successfully."));

                }

                return Content(KendoUiHelper.GetKendoUiWindowAjaxSuccessMethod(Boolean.FalseString, companyViewModel.ActionName, MessageType.warning.ToString(), ExceptionHelper.ModelStateErrorFormat(ModelState)));
            }
            catch (Exception ex)
            {
                return Content(KendoUiHelper.GetKendoUiWindowAjaxSuccessMethod(Boolean.FalseString, companyViewModel.ActionName, MessageType.warning.ToString(), ExceptionHelper.ExceptionMessageFormat(ex)));
            }
        }