Exemple #1
0
        /// <summary>
        /// 新增服务预定信息
        /// </summary>
        /// <param name="webModel">服务预定页视图Model</param>
        /// <param name="context">数据库上下文对象</param>
        /// <returns></returns>
        public static async Task <ServiceInfo> InsertAsync(BookingServiceViewModel webModel, ApplicationDbContext context)
        {
            ServiceInfo model = InsertModel(webModel);

            var user = await PSURepository.GetUserByIdAsync(CurrentUser.UserId, context);

            var service = await AdmissionRepository.GetServiceAsync(Convert.ToInt64(webModel.ServiceId), context);

            if (user == null || service == null)
            {
                return(new ServiceInfo
                {
                    Id = -1
                });
            }

            if (!(Convert.ToDateTime(webModel.DepartureTime) >= service.StartTime && Convert.ToDateTime(webModel.DepartureTime) <= service.EndTime))
            {
                return(new ServiceInfo
                {
                    Id = -2
                });
            }

            model.StudentId = user.Id;
            model.Name      = user.Name;

            model.ServiceId   = service.Id;
            model.ServiceName = service.Name;

            await context.ServiceInfo.AddAsync(model);

            return(model);
        }
Exemple #2
0
 /// <summary>
 /// Insert ServiceInfo Entity
 /// </summary>
 /// <param name="webModel"></param>
 /// <returns></returns>
 private static ServiceInfo InsertModel(BookingServiceViewModel webModel)
 {
     return(new ServiceInfo
     {
         Count = webModel.Count,
         DepartureTime = Convert.ToDateTime(webModel.DepartureTime),
         IsCancel = false,
         Tel = webModel.Tel,
         Place = webModel.Place,
         Remark = webModel.Remark,
     });
 }
        public async Task <IActionResult> BookingService(BookingServiceViewModel webModel)
        {
            if (ModelState.IsValid)
            {
                bool flag;
                if (string.IsNullOrEmpty(webModel.Id))
                {
                    //Add Data
                    int index = await _service.InsertBookingAsync(webModel, _context);

                    if (index == -1)
                    {
                        return(Json(new
                        {
                            success = false,
                            msg = "迎新服务预定失败"
                        }));
                    }

                    if (index == -2)
                    {
                        return(Json(new
                        {
                            success = false,
                            msg = "需要服务时间不在迎新服务提供时间段内"
                        }));
                    }

                    flag = index == 1;
                }
                else
                {
                    return(Json(new
                    {
                        success = false,
                        msg = "迎新服务预定信息禁止修改"
                    }));
                }

                return(Json(new
                {
                    success = flag,
                    msg = flag ? "迎新服务预定成功" : "迎新服务预定失败"
                }));
            }

            return(Json(new
            {
                success = false,
                msg = this.ModelState.Keys.SelectMany(key => this.ModelState[key].Errors).FirstOrDefault().ErrorMessage
            }));
        }
        public async Task <IActionResult> BookingService(string id, bool isBooking)
        {
            BookingServiceViewModel webModel = new BookingServiceViewModel();

            webModel.ServiceId = id;

            if (isBooking)
            {
                //编辑信息,加载迎新服务信息
                webModel = await _service.GetServiceBookingAsync(Convert.ToInt64(id), _context);
            }

            return(View(webModel));
        }
        /// <summary>
        /// 新增当前用户服务预定信息
        /// </summary>
        /// <param name="webModel">编辑页视图Model</param>
        /// <param name="context">数据库连接上下文对象</param>
        /// <returns></returns>
        public async Task <int> InsertBookingAsync(BookingServiceViewModel webModel, ApplicationDbContext context)
        {
            try
            {
                //Add the Service Data
                var model = await RegisterRepository.InsertAsync(webModel, context);

                if (model.Id == -1 || model.Id == -2)
                {
                    return((int)model.Id);
                }

                //Make the transaction commit
                return(await context.SaveChangesAsync());
            }
            catch (Exception ex)
            {
                _logger.LogError("创建迎新服务失败:{0},\r\n内部错误详细信息:{1}", ex.Message, ex.InnerException.Message);
                return(-1);
            }
        }
        /// <summary>
        /// 获取当前用户预定该服务的详细信息
        /// </summary>
        /// <param name="id">服务编号</param>
        /// <param name="context">数据库上下文对象</param>
        /// <returns></returns>
        public async Task <BookingServiceViewModel> GetServiceBookingAsync(long id, ApplicationDbContext context)
        {
            var webModel = new BookingServiceViewModel();

            try
            {
                var model = await RegisterRepository.GetServiceAsync(id, context);

                webModel.Id            = model.Id.ToString();
                webModel.Count         = model.Count;
                webModel.DepartureTime = model.DepartureTime.ToString("yyyy-MM-dd HH:mm");
                webModel.Remark        = model.Remark;
                webModel.ScheduledTime = model.ScheduledTime;
                webModel.ServiceName   = model.ServiceName;
                webModel.Tel           = model.Tel;
                webModel.Place         = model.Place;
            }
            catch (Exception ex)
            {
                _logger.LogError("获取迎新服务预定数据失败:{0},\r\n内部错误信息:{1}", ex.Message, ex.InnerException.Message);
            }
            return(webModel);
        }