예제 #1
0
        /// <summary>
        /// 修改止损申请
        /// </summary>
        /// <param name="user"></param>
        /// <param name="apply"></param>
        /// <param name="stopLossApply"></param>
        /// <param name="details"></param>
        /// <returns></returns>
        public ResultModel Update(UserModel user, NFMT.Operate.Model.Apply apply, NFMT.DoPrice.Model.StopLossApply stopLossApply, List<NFMT.DoPrice.Model.StopLossApplyDetail> details)
        {
            ResultModel result = new ResultModel();
            NFMT.Operate.DAL.ApplyDAL applyDAL = new Operate.DAL.ApplyDAL();
            DAL.StopLossApplyDetailDAL stopLossApplyDetailDAL = new StopLossApplyDetailDAL();

            try
            {
                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    result = applyDAL.Get(user, apply.ApplyId);
                    if (result.ResultStatus != 0)
                        return result;

                    NFMT.Operate.Model.Apply applyResult = result.ReturnValue as NFMT.Operate.Model.Apply;
                    applyResult.ApplyDept = apply.ApplyDept;
                    applyResult.ApplyCorp = apply.ApplyCorp;
                    applyResult.ApplyDesc = apply.ApplyDesc;

                    result = applyDAL.Update(user, applyResult);
                    if (result.ResultStatus != 0)
                        return result;

                    //修改止损申请
                    result = stoplossapplyDAL.Get(user, stopLossApply.StopLossApplyId);
                    if (result.ResultStatus != 0)
                        return result;

                    NFMT.DoPrice.Model.StopLossApply stopLossApplyResult = result.ReturnValue as NFMT.DoPrice.Model.StopLossApply;
                    stopLossApplyResult.StopLossPrice = stopLossApply.StopLossPrice;
                    stopLossApplyResult.StopLossWeight = stopLossApply.StopLossWeight;
                    stopLossApplyResult.Status = StatusEnum.已录入;

                    result = stoplossapplyDAL.Update(user, stopLossApplyResult);
                    if (result.ResultStatus != 0)
                        return result;

                    if (details.Any())
                    {
                        result = stopLossApplyDetailDAL.InvalidAll(user, stopLossApply.StopLossApplyId);
                        if (result.ResultStatus != 0)
                            return result;

                        foreach (Model.StopLossApplyDetail detail in details)
                        {
                            detail.StopLossApplyId = stopLossApply.StopLossApplyId;
                            detail.ApplyId = apply.ApplyId;

                            result = stopLossApplyDetailDAL.Insert(user, detail);
                            if (result.ResultStatus != 0)
                                return result;
                        }
                    }

                    scope.Complete();
                }
            }
            catch (Exception e)
            {
                result.ResultStatus = -1;
                result.Message = e.Message;
            }

            return result;
        }
예제 #2
0
        /// <summary>
        /// 新增止损申请
        /// </summary>
        /// <param name="user"></param>
        /// <param name="apply"></param>
        /// <param name="stopLossApply"></param>
        /// <param name="details"></param>
        /// <returns></returns>
        public ResultModel Create(UserModel user, NFMT.Operate.Model.Apply apply, NFMT.DoPrice.Model.StopLossApply stopLossApply, List<NFMT.DoPrice.Model.StopLossApplyDetail> details)
        {
            ResultModel result = new ResultModel();
            NFMT.Operate.DAL.ApplyDAL applyDAL = new Operate.DAL.ApplyDAL();
            DAL.StopLossApplyDetailDAL stopLossApplyDetailDAL = new StopLossApplyDetailDAL();

            try
            {
                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    NFMT.User.Model.Department dept = NFMT.User.UserProvider.Departments.FirstOrDefault(temp => temp.DeptId == apply.ApplyDept);
                    if (dept == null || dept.DeptId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "申请部门不存在";
                        return result;
                    }

                    //新增主申请
                    apply.EmpId = user.EmpId;
                    apply.ApplyTime = DateTime.Now;
                    apply.ApplyType = NFMT.Operate.ApplyType.StopLossApply;
                    apply.ApplyDept = dept.DeptId;
                    //apply.ApplyDeptName = dept.DeptName;
                    result = applyDAL.Insert(user, apply);
                    if (result.ResultStatus != 0)
                        return result;
                    int applyId = (int)result.ReturnValue;

                    //新增止损申请
                    stopLossApply.ApplyId = applyId;

                    result = stoplossapplyDAL.Insert(user, stopLossApply);
                    if (result.ResultStatus != 0)
                        return result;

                    int stopLossApplyId = (int)result.ReturnValue;

                    if (details.Any())
                    {
                        foreach (Model.StopLossApplyDetail detail in details)
                        {
                            detail.StopLossApplyId = stopLossApplyId;
                            detail.ApplyId = applyId;

                            result = stopLossApplyDetailDAL.Insert(user, detail);
                            if (result.ResultStatus != 0)
                                return result;
                        }
                    }

                    scope.Complete();
                }
            }
            catch (Exception e)
            {
                result.ResultStatus = -1;
                result.Message = e.Message;
            }

            return result;
        }