예제 #1
0
        public ActionResult Create(SBUModel viewModel)
        {
            var strMessage = string.Empty;

            try
            {
                if (ModelState.IsValid)
                {
                    #region Current User

                    var userName = HttpContext.User.Identity.Name;
                    viewModel.IUser = userName;
                    viewModel.IDate = DateTime.Now;
                    viewModel.EDate = DateTime.Now;

                    #endregion

                    var entity = viewModel.ToEntity();
                    _SBUService.BMSUnit.SBURepository.Add(entity);
                    _SBUService.BMSUnit.SBURepository.SaveChanges();

                    return(Content(Boolean.TrueString));
                    //return Content("Information has been saved successfully");
                }

                strMessage = Common.GetModelStateErrorMessage(ModelState);
            }
            catch (Exception ex)
            {
                strMessage = CommonExceptionMessage.GetExceptionMessage(ex, CommonAction.Save);
            }

            return(Content(strMessage));
        }
예제 #2
0
        public ActionResult Edit(SBUModel viewModel)
        {
            var strMessage = string.Empty;

            try
            {
                if (ModelState.IsValid)
                {
                    var model = _SBUService.BMSUnit.SBURepository.GetByID(viewModel.Id);

                    #region Current User

                    viewModel.IUser = model.IUser;
                    viewModel.IDate = model.IDate;

                    var userName = HttpContext.User.Identity.Name;
                    viewModel.EUser = userName;
                    viewModel.EDate = DateTime.Now;

                    #endregion

                    var entity = viewModel.ToEntity();

                    _SBUService.BMSUnit.SBURepository.Update(entity);
                    _SBUService.BMSUnit.SBURepository.SaveChanges();

                    return(Content(Boolean.TrueString));
                }

                strMessage = Common.GetModelStateErrorMessage(ModelState);
            }
            catch (Exception ex)
            {
                strMessage = CommonExceptionMessage.GetExceptionMessage(ex, CommonAction.Update);
            }

            return(Content(strMessage));
        }