コード例 #1
0
        /// <summary>
        /// 添加到数据库
        /// </summary>
        /// <param name="oData"></param>
        /// <param name="coachWageSubList"></param>
        /// <exception cref="Comm.YYException.YYException"></exception>
        private void AddToDB(Models.RequestModel.CreateCoachWageRequest oData, IList <Sys.Models.CoachWages_Sub> coachWageSubList)
        {
            if (coachWageSubList == null || coachWageSubList.Count == 0)
            {
                return;
            }

            Sys.Models.CoachWages coachWage = new Sys.Models.CoachWages()
            {
                AddTime       = DateTime.Now,
                CoachFullName = oData.CurrentCoachFullName,
                CoachID       = oData.CurrentCoachId,
                VenueID       = oData.VenueID,
                WorkDate      = Convert.ToDateTime(oData.WorkDate),
                Price         = coachWageSubList.Sum(c => c.CoachPrice),
                State         = 0,
                Remark        = "待发工资录入",
            };

            bool isExist = false;// IsExist(coachWage.CoachID.Value, coachWage.VenueID.Value, coachWage.WorkDate.Value.ToString("yyyy-MM-dd"));

            if (isExist)
            {
                throw new Comm.YYException.YYException(string.Format("{0} {1} 工资已经录入", coachWage.CoachFullName, oData.WorkDate));
            }
            else
            {
                bool flag = PrePayCoachMoney(coachWage, coachWageSubList);
                if (!flag)
                {
                    throw new Comm.YYException.YYException(string.Format("{0} {1} 工资已经录入", coachWage.CoachFullName, oData.WorkDate));
                }
            }
        }
コード例 #2
0
        public IHttpActionResult Create(dynamic query)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            IList <string> errCoach = new List <string>();
            IList <Sys.Models.CoachWages_Sub> coachWageSubList = new List <Sys.Models.CoachWages_Sub>();

            try
            {
                Models.RequestModel.CreateCoachWageRequest oData = Newtonsoft.Json.JsonConvert.DeserializeObject <Models.RequestModel.CreateCoachWageRequest>(query.ToString());

                if (oData.VenueID <= 0)
                {
                    return(Ok(Comm.ResponseModel.ResponseModelBase.GetRes("场馆编号不能为空")));
                }

                if (string.IsNullOrEmpty(oData.WorkDate))
                {
                    return(Ok(Comm.ResponseModel.ResponseModelBase.GetRes("发工资月份不能为空")));
                }

                //if (oData.CurrentCoachId <= 0)
                //    return Ok(Comm.ResponseModel.ResponseModelBase.GetRes("教练不能为空"));

                if (oData.CurriculumIds == null || oData.CurriculumIds.Count <= 0)
                {
                    return(Ok(Comm.ResponseModel.ResponseModelBase.GetRes("发工资课程不能为空")));
                }

                var result = GetCurriculums(oData.VenueID, oData.WorkDate, oData.CurriculumIds);

                oData.CurrentCoachId       = result.FirstOrDefault().CoachID;
                oData.CurrentCoachFullName = result.FirstOrDefault().CoachFullName;

                foreach (var item in result)
                {
                    if (item.CoachID != oData.CurrentCoachId)
                    {
                        try
                        {
                            AddToDB(oData, coachWageSubList);

                            coachWageSubList = new List <Sys.Models.CoachWages_Sub>();
                        }
                        catch (Comm.YYException.YYException ex)
                        {
                            errCoach.Add(ex.Message);
                        }

                        oData.CurrentCoachId       = item.CoachID;
                        oData.CurrentCoachFullName = item.CoachFullName;
                    }

                    //工资详情表
                    coachWageSubList.Add(new Sys.Models.CoachWages_Sub()
                    {
                        CoachPrice   = item.CoachPrice,
                        CurriculumID = item.CurriculumID,
                        PKID         = item.PKID,
                        AddTime      = DateTime.Now
                    });
                }

                try
                {
                    AddToDB(oData, coachWageSubList);
                }
                catch (Comm.YYException.YYException ex)
                {
                    errCoach.Add(ex.Message);
                }

                return(Ok(new Comm.ResponseModel.ResponseModel4Res <string>()
                {
                    Error = errCoach.Count > 0,
                    Msg = string.Join(",", errCoach)
                }));
            }
            catch (Comm.YYException.YYException ex)
            {
                return(Ok(Comm.ResponseModel.ResponseModelBase.GetRes(ex.Message)));
            }
            catch (Exception ex)
            {
                logs.Error("录入工资失败", ex);
                return(BadRequest());
            }
        }