Ejemplo n.º 1
0
        public ActionResult Create(ConditionDetailView conditionDetailView)
        {
            conditionDetailView.EmployeeView = GetEmployee();

            #region Access Check
            bool hasPermission = GetEmployee().IsGuaranteed("Condition_Insert");
            if (!hasPermission)
            {
                ModelState.AddModelError("", "AccessDenied");
                return(View(conditionDetailView));
            }
            #endregion

            if (ModelState.IsValid)
            {
                try
                {
                    AddConditionRequestOld request = new AddConditionRequestOld();
                    request.CreateEmployeeID = GetEmployee().ID;
                    request.ConditionTitle   = conditionDetailView.ConditionView.ConditionTitle;
                    //request.CriteriaOperator = conditionDetailView.ConditionView.CriteriaOperator;
                    request.ErrorText  = conditionDetailView.ConditionView.ErrorText;
                    request.nHibernate = conditionDetailView.ConditionView.nHibernate;
                    //request.PropertyName = conditionDetailView.ConditionView.PropertyName;
                    request.QueryText = conditionDetailView.ConditionView.QueryText;
                    //request.Value = conditionDetailView.ConditionView.Value;


                    GeneralResponse response = this._conditionService.AddCondition(request);

                    if (response.success)
                    {
                        return(RedirectToAction("Index"));
                    }
                    else
                    {
                        foreach (string error in response.ErrorMessages)
                        {
                            ModelState.AddModelError("", error);
                        }
                        return(View(conditionDetailView));
                    }
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("", ex.Message);
                    return(View(conditionDetailView));
                }
            }

            return(View(conditionDetailView));
        }
Ejemplo n.º 2
0
        public GeneralResponse AddCondition(AddConditionRequestOld request)
        {
            GeneralResponse response = new GeneralResponse();

            try
            {
                Condition condition = new Condition();
                condition.ID             = Guid.NewGuid();
                condition.CreateDate     = PersianDateTime.Now;
                condition.CreateEmployee = _employeeRepository.FindBy(request.CreateEmployeeID);
                condition.ConditionTitle = request.ConditionTitle;
                //condition.CriteriaOperator = request.CriteriaOperator;
                condition.ErrorText  = request.ErrorText;
                condition.nHibernate = request.nHibernate;
                //condition.PropertyName = request.PropertyName;
                condition.QueryText = request.QueryText;
                //condition.Value = request.Value;
                condition.RowVersion = 1;

                #region Validation
                if (condition.GetBrokenRules().Count() > 0)
                {
                    foreach (BusinessRule businessRule in condition.GetBrokenRules())
                    {
                        response.ErrorMessages.Add(businessRule.Rule);
                    }

                    return(response);
                }
                #endregion

                _conditionRepository.Add(condition);
                _uow.Commit();

                ////response.success = true;
            }
            catch (Exception ex)
            {
                response.ErrorMessages.Add(ex.Message);

                if (ex.InnerException != null)
                {
                    response.ErrorMessages.Add("FIRST INNER EXPCEPTION: " + ex.InnerException.Message);
                    if (ex.InnerException.InnerException != null)
                    {
                        response.ErrorMessages.Add("SECOND INNER EXPCEPTION: " + ex.InnerException.InnerException.Message);
                    }
                }
            }

            return(response);
        }