标签:
CRUD
public class UpdateCommitteeBll : BllBaseEx { /// <summary> /// 要求キー-委員会 /// </summary> public const string REQUEST_KEY_COMMITTEE = "DB_COMMITTEE_REGISTER_COMMITTEE"; /// <summary> /// 要求キー-出席者 /// </summary> public const string REQUEST_KEY_ATTENDEE = "DB_COMMITTEE_REGISTER_ATTENNDEE"; /// <summary> /// 返却キー-委員会No /// </summary> public const string RESPONSE_KEY_COMMITTEE_NO = "DB_COMMITTEE_REGISTER_COMMITTEE_NO"; /// <summary> /// /// </summary> /// <returns></returns> protected override Dictionary<string, object> Perform() { DateTime now = DateTime.Now; TBAAMS_COMMITTEE committee = Request[REQUEST_KEY_COMMITTEE] as TBAAMS_COMMITTEE; List<RESULT_ATTENDEE> attendee = Request[REQUEST_KEY_ATTENDEE] as List<RESULT_ATTENDEE>; TBAAMS_COMMITTEE result = (from row in DataContext.TBAAMS_COMMITTEE where row.COMMITTEE_NO == committee.COMMITTEE_NO select row).FirstOrDefault(); //委員会 if (result == null) { //登録処理 committee.COMMITTEE_NO = ApplicationBllUtility.GenerateCommitteeNo(DataContext); committee.HOLD_INFORM_FLG = ‘0‘; committee.PROGRAM_INFORM_FLG = ‘0‘; committee.DISCUSSION_RESULT_INFORM_FLG = ‘0‘; committee.DEL_FLG = ‘0‘; committee.INS_USERID = this.StaffInfo.StfCd; committee.INS_IP = this.StaffInfo.Ip; committee.INS_DATE = now; committee.UPD_USERID = this.StaffInfo.StfCd; committee.UPD_IP = this.StaffInfo.Ip; committee.UPD_DATE = now; DataContext.TBAAMS_COMMITTEE.InsertOnSubmit(committee); } else { //更新処理 //排他処理チェック if (result.UPD_IP == committee.UPD_IP && result.UPD_USERID == committee.UPD_USERID && result.UPD_DATE == committee.UPD_DATE) { result.HOLD_DATE = committee.HOLD_DATE; result.HOLD_PLACE = committee.HOLD_PLACE; result.START_TIME = committee.START_TIME; result.END_TIME = committee.END_TIME; result.REMARKS = committee.REMARKS; result.UPD_USERID = this.StaffInfo.StfCd; result.UPD_IP = this.StaffInfo.Ip; result.UPD_DATE = now; } else { //排他エラー throw new Exception(Messages.ERROR013.Replace("{0}", "委員会")); } } //出席者(Delete-Insert) List<TBAARS_COMMITTEE_ATTENDEE> resDel = (from delRow in DataContext.TBAARS_COMMITTEE_ATTENDEE where delRow.COMMITTEE_NO == committee.COMMITTEE_NO select delRow).ToList (); DataContext.TBAARS_COMMITTEE_ATTENDEE.DeleteAllOnSubmit (resDel); foreach (RESULT_ATTENDEE insRow in attendee) { if (insRow.ATTENDEE_FLG .Equals (‘1‘)) { TBAARS_COMMITTEE_ATTENDEE insAttendee = new TBAARS_COMMITTEE_ATTENDEE(); insAttendee.COMMITTEE_NO = committee.COMMITTEE_NO; insAttendee.STF_CODE = insRow.STF_CODE; insAttendee.DEL_FLG = ‘0‘; insAttendee.INS_USERID = this.StaffInfo.StfCd; insAttendee.INS_IP = this.StaffInfo.Ip; insAttendee.INS_DATE = now; insAttendee.UPD_USERID = this.StaffInfo.StfCd; insAttendee.UPD_IP = this.StaffInfo.Ip; insAttendee.UPD_DATE = now; DataContext.TBAARS_COMMITTEE_ATTENDEE.InsertOnSubmit(insAttendee); } } Dictionary<string, object> response = new Dictionary<string, object>(); response.Add(RESPONSE_KEY_COMMITTEE_NO, committee.COMMITTEE_NO ); return response; } protected override void Validate() { base.Validate(); TBAAMS_COMMITTEE committee = Request[REQUEST_KEY_COMMITTEE] as TBAAMS_COMMITTEE; List<RESULT_ATTENDEE> attendee = Request[REQUEST_KEY_ATTENDEE] as List<RESULT_ATTENDEE>; MessageException ex = new MessageException(); //開催日 //必須チェック if (String.IsNullOrEmpty (committee.HOLD_DATE)) { ex.Messages.Add(string.Format(Messages.ERROR001, "開催日")); } //開催場所 //必須チェック if (String.IsNullOrEmpty(committee.HOLD_PLACE )) { ex.Messages.Add(string.Format(Messages.ERROR001, "開催場所")); } //時間 //前後チェック if (!string.IsNullOrEmpty(committee.START_TIME) && !string.IsNullOrEmpty(committee.END_TIME)) { if (!CheckUtility.CheckTimeBigAndSmall( committee.START_TIME.Split (‘:‘)[0], committee.START_TIME.Split (‘:‘)[1], committee.END_TIME.Split (‘:‘)[0], committee.END_TIME.Split (‘:‘)[1])) { ex.Messages.Add("開始時間と終了時間の前後関係が正しくありません。"); } } //出席者 //委員の出席者に1人でも出席者がいるかをチェック var chk = (from row in attendee where row.ATTENDEE_FLG == ‘1‘ && (row.ROLE_CODE == Role.Committee .Value || row.ROLE_CODE == Role.Chairperson .Value ) select row).ToList (); if(chk.Count == 0){ ex.Messages.Add(string.Format(Messages.ERROR010.Replace (‘が‘,‘も‘), "出席委員が1人")); } if (ex.Messages.Count != 0) { throw ex; } } }
标签:
原文地址:http://www.cnblogs.com/haiy/p/4155675.html