public IHttpActionResult AddDeMerit(DeMeritDataViewModel deMeritView) { try { string errorMessage = String.Empty; DeMerit deMerit = new DeMerit(); if (deMeritView != null) { deMerit.DeMeritNo = deMeritView.deMeritNo; deMerit.InqueryDate = deMeritView.inqueryDate; deMerit.MemberId = deMeritView.member.id; deMerit.BusId = deMeritView.bus.id; deMerit.RouteId = deMeritView.route.id; deMerit.OfficeriId = deMeritView.officer.id; deMerit.CreatedDate = TimeZoneInfo.ConvertTime(DateTime.Now, TimeZoneInfo.FindSystemTimeZoneById(ConfigurationManager.AppSettings["LocalTimeZone"])); deMerit.MemberDeMerits = new List <MemberDeMerit>(); foreach (MemberDeMeritViewModel memberDemerit in deMeritView.memberDeMerit) { MemberDeMerit demerit = new MemberDeMerit(); demerit.DeMeritId = deMerit.ID; demerit.MeritId = memberDemerit.meritId; if (memberDemerit.isSelected) { demerit.Point = 1; } else { demerit.Point = 0; } deMerit.MemberDeMerits.Add(demerit); } _deMerit.Add(deMerit, out errorMessage); } else { errorMessage = Constant.MessageGeneralError; } var messageData = new { code = String.IsNullOrEmpty(errorMessage) ? Constant.SuccessMessageCode : Constant.ErrorMessageCode , message = String.IsNullOrEmpty(errorMessage) ? Constant.MessageSuccess : errorMessage }; var returnObject = new { messageCode = messageData }; return(Ok(returnObject)); } catch (Exception ex) { string errorLogId = _eventLog.WriteLogs(User.Identity.Name, ex, MethodBase.GetCurrentMethod().Name); var messageData = new { code = Constant.ErrorMessageCode, message = String.Format(Constant.MessageTaskmateError, errorLogId) }; var returnObject = new { messageCode = messageData }; return(Ok(returnObject)); } }
public IHttpActionResult GetDemeritByNo(int deMeritNo) { try { DeMeritViewModel deMeritView = new DeMeritViewModel(); DeMerit deMerit = new DeMerit(); deMerit = _deMerit.GetDeMeritByNo(deMeritNo); if (deMerit != null) { deMeritView.id = deMerit.ID; deMeritView.deMeritNo = deMerit.DeMeritNo; deMeritView.inqueryDate = deMerit.InqueryDate.ToString(@"yyyy-MM-dd"); deMeritView.member = new MemberViewModel(); deMeritView.member.id = deMerit.MemberId; deMeritView.member.nameWithInitial = deMerit.Member.ShortName; deMeritView.inqueryDate = deMerit.InqueryDate.ToString(@"yyyy-MM-dd"); deMeritView.officer = new OfficerViewModel(); deMeritView.officer.id = deMerit.Officer.ID; deMeritView.officer.name = deMerit.Officer.Name; deMeritView.bus = new BusViewModel(); deMeritView.bus.id = deMerit.Bus.ID; deMeritView.bus.busNo = deMerit.Bus.LicenceNo; deMeritView.memberDeMerit = new List <MemberDeMeritViewModel>(); foreach (MemberDeMerit merti in deMerit.MemberDeMerits) { MemberDeMeritViewModel demerit = new MemberDeMeritViewModel(); demerit.id = merti.ID; demerit.meritId = merti.MeritId; demerit.code = merti.Merit.Code; demerit.description = merti.Merit.Description; demerit.point = merti.Point; demerit.colorCode = merti.Merit.ColorCodeId; deMeritView.memberDeMerit.Add(demerit); } } var messageData = new { code = Constant.SuccessMessageCode, message = Constant.MessageSuccess }; var returnObject = new { demerit = deMeritView, messageCode = messageData }; return(Ok(returnObject)); } catch (Exception ex) { string errorLogId = _eventLog.WriteLogs(User.Identity.Name, ex, MethodBase.GetCurrentMethod().Name); var messageData = new { code = Constant.ErrorMessageCode, message = String.Format(Constant.MessageTaskmateError, errorLogId) }; var returnObject = new { messageCode = messageData }; return(Ok(returnObject)); } }
public IHttpActionResult GetBestMember() { try { DeMerit deMerit = new DeMerit(); deMerit = _deMerit.GetLastDeMeritNo(); DateTime date = TimeZoneInfo.ConvertTime(DateTime.Now, TimeZoneInfo.FindSystemTimeZoneById(ConfigurationManager.AppSettings["LocalTimeZone"])); string today = date.ToShortDateString().Replace("/", String.Empty); string nextdeMeritNo = String.Empty; if (deMerit != null) { string deMeritNo = deMerit.DeMeritNo; string deMeritdate = deMeritNo.Split('-')[0]; int no = int.Parse(deMeritNo.Split('-')[1]); if (deMeritdate == today) { nextdeMeritNo = deMeritdate + "-" + (no + 1); } else { nextdeMeritNo = today + "-" + "1"; } } else { nextdeMeritNo = today + "-" + "1"; } var messageData = new { code = Constant.SuccessMessageCode, message = Constant.MessageSuccess }; var returnObject = new { complainNo = nextdeMeritNo, messageCode = messageData }; return(Ok(returnObject)); } catch (Exception ex) { string errorLogId = _eventLog.WriteLogs(User.Identity.Name, ex, MethodBase.GetCurrentMethod().Name); var messageData = new { code = Constant.ErrorMessageCode, message = String.Format(Constant.MessageTaskmateError, errorLogId) }; var returnObject = new { messageCode = messageData }; return(Ok(returnObject)); } }