Esempio n. 1
0
        public ActionResult InsertGoOutReason(string key, string values)
        {
            try
            {
                var newGoOutReason = new GoOutReasonViewModel();
                JsonConvert.PopulateObject(values, newGoOutReason);

                //Combine Date and Time Label
                DateTime tmpStartTime = new DateTime(newGoOutReason.StartDate.Year, newGoOutReason.StartDate.Month, newGoOutReason.StartDate.Day
                                                     , newGoOutReason.StartTime.Hour, newGoOutReason.StartTime.Minute, newGoOutReason.StartTime.Second);
                DateTime tmpEndTime = new DateTime(newGoOutReason.EndDate.Year, newGoOutReason.EndDate.Month, newGoOutReason.EndDate.Day
                                                   , newGoOutReason.EndTime.Hour, newGoOutReason.EndTime.Minute, newGoOutReason.EndTime.Second);

                newGoOutReason.StartTime = tmpStartTime;
                newGoOutReason.EndTime   = tmpEndTime;

                ValidateModel(newGoOutReason);
                if (!ModelState.IsValid)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, ModelState.ToString()));
                }

                SaveGoOutReasonResult result = new SaveGoOutReasonResult();
                if (newGoOutReason.StartTime > newGoOutReason.EndTime)
                {
                    result.ErrorType    = ConstantValues.TypeWarning;
                    result.ErrorMessage = String.Format(MessageListResource.W0001, "Date");
                    return(Content(JsonConvert.SerializeObject(result), ConstantValues.JSON_CONTENT_TYPE));
                }

                newGoOutReason.UpdateBy = UserDetail.UserID;
                result = TransactionService.SaveGoOutReason(newGoOutReason.ToEntity(), ConstantValues.ADD);

                return(Content(JsonConvert.SerializeObject(GetMsgFromInsertUpdateActionResult(result)), ConstantValues.JSON_CONTENT_TYPE));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 2
0
        public SaveGoOutReasonResult GetMsgFromInsertUpdateActionResult(SaveGoOutReasonResult result)
        {
            try
            {
                if (result.ErrorCode == "0")
                {
                    result.ErrorMessage = MessageListResource.I0001;
                }
                else if (result.ErrorCode == "1")
                {
                    result.ErrorMessage = String.Format(MessageListResource.W0003, result.ErrorMessage);
                }
                else if (result.ErrorCode == "2")
                {
                    result.ErrorMessage = String.Format(MessageListResource.W0004, result.ErrorMessage);
                }
                else if (result.ErrorCode == "3")
                {
                    result.ErrorMessage = String.Format(MessageListResource.W0005, "Go Out Reason", "Time");
                }
                else if (result.ErrorCode == "4")
                {
                    result.ErrorMessage = String.Format(MessageListResource.E0005, "Go Out Reason");
                }
                else if (result.ErrorCode == "9")
                {
                    result.ErrorMessage = String.Format(MessageListResource.E0003, "save", result.ErrorMessage);
                }

                return(result);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }