Example #1
0
        public IActionResult CreateRangeAsync([FromBody] YachtNonBusinessDayCreateRangeModel createModel)
        {
            if (createModel == null || string.IsNullOrEmpty(createModel.NonBusinessDay))
            {
                return(BadRequest());
            }
            var result = _yachtNonBusinessDaysService.CreateRangeAsync(createModel).Result;

            if (result.IsSuccessStatusCode)
            {
                return(Ok(result));
            }
            return(BadRequest());
        }
        public async Task <BaseResponse <bool> > CreateRangeAsync(YachtNonBusinessDayCreateRangeModel createModel)
        {
            try
            {
                var listNonBusinessDay = createModel.NonBusinessDay.Split(",");
                var listCreate         = new List <YachtNonOperationDays>();
                foreach (var nonBusinessDay in listNonBusinessDay)
                {
                    var date     = nonBusinessDay.Replace(".", "-");
                    var dateTime = (date + "-" + DateTime.Now.Year).ToNullDateTime();
                    if (dateTime != null)
                    {
                        var model = new YachtNonOperationDays()
                        {
                            YachtFid         = createModel.YachtFid,
                            Recurring        = createModel.Recurring,
                            Remark           = createModel.Remark,
                            StartDate        = dateTime.Value,
                            EndDate          = dateTime.Value,
                            CreatedBy        = GetUserGuidId(),
                            CreatedDate      = DateTime.Now,
                            Deleted          = false,
                            LastModifiedBy   = GetUserGuidId(),
                            LastModifiedDate = DateTime.Now
                        };
                        listCreate.Add(model);
                    }
                }
                await _context.YachtNonOperationDays.AddRangeAsync(listCreate);

                await _context.SaveChangesAsync();

                return(BaseResponse <bool> .Success(true));
            }
            catch (Exception ex)
            {
                return(BaseResponse <bool> .InternalServerError(message : ex.Message, fullMsg : ex.StackTrace));
            }
        }