public int AddStrataAdminBookingRequest(BookingRequestModel strataOwnerBookingRequestModel) { int result = 0; try { tblUserBookingRequest tblUserBookingRequestDb = new tblUserBookingRequest(); tblUserBookingRequestDb.UserClientId = ClientSessionData.UserClientId; tblUserBookingRequestDb.Subject = strataOwnerBookingRequestModel.Subject; tblUserBookingRequestDb.FromDate = !string.IsNullOrEmpty(strataOwnerBookingRequestModel.FromDate) ? Convert.ToDateTime(strataOwnerBookingRequestModel.FromDate) : (DateTime?)null; tblUserBookingRequestDb.ToDate = !string.IsNullOrEmpty(strataOwnerBookingRequestModel.ToDate) ? Convert.ToDateTime(strataOwnerBookingRequestModel.ToDate) : (DateTime?)null; tblUserBookingRequestDb.Reason = strataOwnerBookingRequestModel.Reason; tblUserBookingRequestDb.Status = int.Parse(strataOwnerBookingRequestModel.Status); tblUserBookingRequestDb.AdminStatus = strataOwnerBookingRequestModel.AdminStatus; tblUserBookingRequestDb.CommonAreaId = strataOwnerBookingRequestModel.CommonAreaId; tblUserBookingRequestDb.CreatedOn = DateTime.UtcNow; tblUserBookingRequestDb.ModifiedOn = DateTime.UtcNow; tblUserBookingRequestDb.StratasBoardId = ClientSessionData.ClientStrataBoardId; // Get all the records related to that particular strataboard var UserRequests = _context.tblUserBookingRequests.Where(x => x.StratasBoardId == ClientSessionData.ClientStrataBoardId && x.CommonAreaId == strataOwnerBookingRequestModel.CommonAreaId && x.Status != 2).ToList(); if (UserRequests != null && UserRequests.Count > 0) { foreach (var item in UserRequests) { // Check any other booking is not there in the requested time slot if ((Convert.ToDateTime(strataOwnerBookingRequestModel.FromDate) >= item.FromDate && Convert.ToDateTime(strataOwnerBookingRequestModel.FromDate) <= item.ToDate) || (Convert.ToDateTime(strataOwnerBookingRequestModel.ToDate) >= item.FromDate && Convert.ToDateTime(strataOwnerBookingRequestModel.ToDate) <= item.ToDate) || (Convert.ToDateTime(strataOwnerBookingRequestModel.FromDate) <= item.FromDate && Convert.ToDateTime(strataOwnerBookingRequestModel.ToDate) >= item.ToDate)) { result = -1; break; } } } if (result == 0) { _context.tblUserBookingRequests.Add(tblUserBookingRequestDb); result = _context.SaveChanges(); } } catch (Exception ex) { new AppError().LogMe(ex); result = -2; } return(result); }
public int AddStrataOwnerBookingRequest(StrataOwnerBookingRequestModel strataOwnerBookingRequestModel) { int result = 0; try { tblUserBookingRequest tblUserBookingRequestDb = new tblUserBookingRequest(); tblUserBookingRequestDb.UserClientId = ClientSessionData.UserClientId; tblUserBookingRequestDb.Subject = strataOwnerBookingRequestModel.Subject; tblUserBookingRequestDb.FromDate = !string.IsNullOrEmpty(strataOwnerBookingRequestModel.FromDate) ? Convert.ToDateTime(strataOwnerBookingRequestModel.FromDate) : (DateTime?)null; tblUserBookingRequestDb.ToDate = !string.IsNullOrEmpty(strataOwnerBookingRequestModel.ToDate) ? Convert.ToDateTime(strataOwnerBookingRequestModel.ToDate) : (DateTime?)null; tblUserBookingRequestDb.Reason = strataOwnerBookingRequestModel.Reason; tblUserBookingRequestDb.Status = int.Parse(strataOwnerBookingRequestModel.Status); tblUserBookingRequestDb.AdminStatus = 1; tblUserBookingRequestDb.CommonAreaId = strataOwnerBookingRequestModel.CommonAreaId; tblUserBookingRequestDb.CreatedOn = DateTime.UtcNow; tblUserBookingRequestDb.ModifiedOn = DateTime.UtcNow; tblUserBookingRequestDb.StratasBoardId = ClientSessionData.ClientStrataBoardId; var UserRequests = _context.tblUserBookingRequests.Where(x => x.UserClientId == ClientSessionData.UserClientId && x.CommonAreaId == strataOwnerBookingRequestModel.CommonAreaId && x.Status != 2).FirstOrDefault(); if (UserRequests != null) { if (UserRequests.FromDate > Convert.ToDateTime(strataOwnerBookingRequestModel.ToDate) || UserRequests.ToDate < Convert.ToDateTime(strataOwnerBookingRequestModel.FromDate)) { _context.tblUserBookingRequests.Add(tblUserBookingRequestDb); result = _context.SaveChanges(); } else { result = -1; } } else { _context.tblUserBookingRequests.Add(tblUserBookingRequestDb); result = _context.SaveChanges(); } } catch { } return(result); }
/// <summary> /// Update the booking status from StratasBoard Admin /// </summary> /// <param name="model"></param> /// <returns></returns> public int UpdateAdminBookingStatus(BookingRequestModel model) { try { tblUserBookingRequest objModel = new tblUserBookingRequest(); objModel = context.tblUserBookingRequests.Where(x => x.BookingRequestId == model.BookingRequestId && x.Status == 1).FirstOrDefault(); objModel.AdminUserId = ClientSessionData.UserClientId; objModel.ModifiedOn = DateTime.UtcNow; objModel.AdminRemark = model.AdminRemark; objModel.AdminStatus = model.AdminStatus; context.tblUserBookingRequests.Attach(objModel); context.Entry(objModel).Property(x => x.AdminUserId).IsModified = true; context.Entry(objModel).Property(x => x.ModifiedOn).IsModified = true; context.Entry(objModel).Property(x => x.AdminRemark).IsModified = true; context.Entry(objModel).Property(x => x.AdminStatus).IsModified = true; return(context.SaveChanges()); } catch { return(-1); } }