Exemple #1
0
        public void Add(TimeFrameRequestCreate request)
        {
            request.Duration = request.EndTime - request.StartTime;
            request.Active   = true;
            var entity = mapper.Map <TimeFrameRequestCreate, TimeFrame>(request);

            entity.CheckInExpandTime    = new TimeSpan(1, 0, 0);
            entity.CheckOutExpandTime   = new TimeSpan(1, 0, 0);
            entity.ComeLateExpandTime   = new TimeSpan(1, 0, 0);
            entity.LeaveEarlyExpandTime = new TimeSpan(1, 0, 0);
            Create(entity);
        }
        public ActionResult Create(TimeFrameRequestCreate request)
        {
            HttpResponseMessage httpResponseMessage = new HttpResponseMessage()
            {
                StatusCode = HttpStatusCode.OK
            };
            BaseResponse <dynamic> response = new BaseResponse <dynamic>();
            JsonResult             result   = new JsonResult(response)
            {
                StatusCode = (int)HttpStatusCode.OK
            };

            try
            {
                #region check model
                //if (!ModelState.IsValid)
                //{
                //    var modelState = ModelState.FirstOrDefault();
                //    var error = modelState.Value.Errors.FirstOrDefault().ErrorMessage;
                //    throw ApiException.Get(false, error, ResultEnum.ModelError, HttpStatusCode.BadRequest);
                //}
                #endregion

                timeFrameService.Add(request);
                response = BaseResponse <dynamic> .Get(true, ConstantManager.CreateSuccess("Time frame :"), null, ResultEnum.Success);
            }
            catch (ApiException e)
            {
                result.StatusCode = e.StatusCode;
                response          = BaseResponse <dynamic> .Get(e.Success, e.ErrorMessage, null, e.ErrorStatus);

                result = new JsonResult(response);
            }
            catch (Exception e)
            {
                result.StatusCode = (int)HttpStatusCode.InternalServerError;
                response          = BaseResponse <dynamic> .Get(false, ConstantManager.Fail("Time frame : ") + e.ToString(), null, ResultEnum.InternalError);
            }
            result = new JsonResult(response);
            return(result);
        }