Esempio n. 1
0
        private void UpdateConditionDetails(ConditionDataContract dt)
        {
            var handler = DataAccess.Core.GetFactory().GetInstance <IConditionDetailHandler>();
            var list    = handler.GetAll(dt.Id);


            //add new fields
            foreach (ConditionDetailDataContract item in dt.ConditionDetails)
            {
                if (list.Where(o => o.Id.Equals(item.Id)).Any())
                {
                    continue;
                }
                else
                {
                    item.ConditionId = dt.Id;
                    handler.Add(item);
                }
            }

            list = handler.GetAll(dt.Id);

            //remove deleted fields
            foreach (var item in list)
            {
                if (dt.ConditionDetails.Where(o => o.Id.Equals(item.Id)).Any())
                {
                    continue;
                }
                else
                {
                    handler.Delete(item);
                }
            }
        }
Esempio n. 2
0
        public Common.OperationResult Update(ConditionDataContract dataContract)
        {
            var handler = DataAccess.Core.GetFactory().GetInstance <IConditionHandler>();

            dataContract.UpdatedBy = Common.SessionData.ResourceId;
            dataContract.UpdatedOn = DateTime.Now;

            var val = dataContract.Validate();

            if (!val.IsValid)
            {
                return(new Common.OperationResult(val));
            }

            if (dataContract.ConditionDetails != null && dataContract.ConditionDetails.Count() > 0)
            {
                dataContract.GeneratedCommand = GetCommandText(dataContract.ConditionDetails, dataContract.EntityId);
            }

            var result = handler.Update(dataContract);

            if (result.Status == Common.OperationResultStatus.Succesfull)
            {
                UpdateConditionDetails(dataContract);
            }

            return(result);
        }
Esempio n. 3
0
        public string GetDisplayText(ConditionDataContract dt)
        {
            switch (dt.ConditionType)
            {
            case "P":
                return(dt.StoredProcedure);

            case "S":
                return(dt.SQLCommand);

            default:
                return(GetDisplayText(dt.ConditionDetails, dt.EntityId));
            }
        }
Esempio n. 4
0
        public ActionResult EditCondition(ConditionModel model)
        {
            var conditionBO = BusinessLogic.Core.GetFactory().GetInstance <BusinessLogic.BusinessObject.IConditionBO>();

            ConditionDataContract dt = new ConditionDataContract();

            bool update;

            if (model.Id.Equals(Guid.Empty))
            {
                update = false;
                dt.Id  = Guid.NewGuid();
            }
            else
            {
                update = true;
                dt     = conditionBO.GetById(model.Id);
            }

            dt.Name          = model.Name;
            dt.ConditionType = model.ConditionType;
            dt.EntityId      = model.EntityId;

            var list = (List <ConditionDetailModel>)Session["ConditionDetailList"];

            if (model.ConditionType == "M")
            {
                dt.ConditionDetails = list.Select(o => new ConditionDetailDataContract()
                {
                    Id = o.ConditionDetailId, Field = o.Field, GroupIdentifier = o.GroupIdentifier, Operator = o.Operator, Value1 = o.Value1, Value2 = o.Value2
                });
                dt.SQLCommand      = string.Empty;
                dt.StoredProcedure = string.Empty;
            }
            else if (model.ConditionType == "P")
            {
                dt.ConditionDetails = new List <ConditionDetailDataContract>();
                dt.SQLCommand       = string.Empty;
                dt.StoredProcedure  = model.SQLProcedure;
            }
            else if (model.ConditionType == "S")
            {
                dt.ConditionDetails = new List <ConditionDetailDataContract>();
                dt.SQLCommand       = model.SQLCommand;
                dt.StoredProcedure  = string.Empty;
            }

            OperationResult result;

            if (update)
            {
                result = conditionBO.Update(dt);
            }
            else
            {
                result = conditionBO.Add(dt);
            }

            if (result.Status != OperationResultStatus.Succesfull)
            {
                ModelState.AddModelError("", result.Message);
                return(View(model));
            }
            else
            {
                return(RedirectToAction("ConditionList", "Condition"));
            }
        }