Exemple #1
0
        public async Task <ActionResult <ReservationDetail> > PostReservationDetail(ReservationDetail reservationDetail)
        {
            _context.ReservationDetails.Add(reservationDetail);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetReservationDetail", new { id = reservationDetail.ResID }, reservationDetail));
        }
        public IHttpActionResult PostReservationDetail(ReservationDetail reservationDetail)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.ReservationDetails.Add(reservationDetail);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (ReservationDetailExists(reservationDetail.PNRNo))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = reservationDetail.PNRNo }, reservationDetail));
        }
        public IHttpActionResult PutReservationDetail(string id, ReservationDetail reservationDetail)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != reservationDetail.PNRNo)
            {
                return(BadRequest());
            }

            db.Entry(reservationDetail).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ReservationDetailExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemple #4
0
        public async Task <IActionResult> PutReservationDetail(int id, ReservationDetail reservationDetail)
        {
            if (id != reservationDetail.ResID)
            {
                return(BadRequest());
            }

            _context.Entry(reservationDetail).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ReservationDetailExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemple #5
0
        public IActionResult CompleteDetail(int id, string token)
        {
            DutyMember member = VerifyDutyMemberLogIn();

            if (member == null)
            {
                return(new JsonResult(new { result = false }));
            }

            if (VerifyDutyMemberDetailToken(member, id.ToString(), token) == false)
            {
                return(new JsonResult(new { result = false }));
            }

            ReservationDetail detail = (from d in db.ReservationDetails where d.Id == id select d).FirstOrDefault();

            if (detail == null)
            {
                return(new JsonResult(new { result = false }));
            }

            if (detail.DutyMember == member && detail.State == ReservationState.Answered)
            {
                detail.State           = ReservationState.Completed;
                detail.ActionDate      = DateTimeHelper.GetBeijingTime();
                db.Entry(detail).State = EntityState.Modified;
                db.SaveChanges();
                return(new JsonResult(new { result = true }));
            }
            else
            {
                return(new JsonResult(new { result = false }));
            }
        }
        private IActionResult ActionComplete(ReservationDetail _detail, int rate, string content)
        {
            if (_detail == null)
            {
                return(RedirectToActionPermanent(nameof(Index)));
            }

            if (_detail.State == ReservationState.Answered)
            {
                _detail.State = ReservationState.Completed;
                _detail.LastUpdatedLanguage = cultureContext.Culture.Language;
                _detail.ActionDate          = DateTimeHelper.GetBeijingTime();
                EntityEntry <ReservationDetail> entry = db.Entry(_detail);
                entry.State = EntityState.Modified;

                ServiceFeedback fb = new ServiceFeedback()
                {
                    Content           = content,
                    Rate              = rate,
                    ReservationDetail = _detail
                };
                db.ServiceFeedBacks.Add(fb);
                db.SaveChanges();
            }
            return(RedirectToActionPermanent(nameof(Detail)));
        }
Exemple #7
0
        /// <summary>
        /// Checks whether given reservation can be added or not. Performs logical and business validation.
        /// </summary>
        public ValidationResult ValidateReservationEntry(ReservationDetail newReservation)
        {
            if (newReservation == null)
            {
                throw new ArgumentNullException("Null argument: newReservation");
            }

            var result = Models.ValidationResult.Default;

            // TODO: Implement validation
            // Remember ! Check ALL validation rules and set result with appropriate enum flag described above.
            // Note that for reservation dates, we take into account only date and an hour, minutes and seconds don't matter.

            // Validation rules:
            // - Validation routine checks for all possible errors to provide full details, instead of stopping at first error (that's why [Flags] is used)
            // - newReservation.From must be the same day as newReservation.To. If it isn't, set result |= ValidationResult.MoreThanOneDay
            // - newReservation.From cannot be >= newReservation.To. If it is, set result |= ValidationResult.ToBeforeFrom
            // - whole newReservation must be included inside working hours: 7-18 (it can't start before 7 and must finish at 18 at the very latest).
            //		If it's not met, set result |= ValidationResult.OutsideWorkingHours
            // - newReservation must last 1 hours at most. If it's not, set result |= ValidationResult.TooLong
            // - newReservation cannot be in conflict (same asset id) with any existing reservation.
            //   If it is, set result |= ValidationResult.Conflicting.
            // - check if newReservation.AssetId points at existing asset. If it's not, set result |= ValidationResult.AssetDoesNotExist.

            if (result == ValidationResult.Default)
            {
                result = ValidationResult.Ok;
            }

            return(result);
        }
Exemple #8
0
        public void DeleteReservationMaterial(Reservation res, MaterialIdentifier mat)
        {
            ReservationDetail resDetail = res.Details.First(r => r.MaterialIdentifier == mat);

            Reservations.First(r => r.Id == res.Id).Details.Remove(resDetail);
            IIMContext.Create().Entry(resDetail).State = EntityState.Deleted;
        }
        public IHttpActionResult PostReservationDetail(ReservationDetail ReservationDetail)
        {
            db.ReservationDetails.Add(ReservationDetail);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = ReservationDetail.ReservationID }, ReservationDetail));
        }
        public IHttpActionResult PutReservationDetail(int id, ReservationDetail ReservationDetail)
        {
            if (id != ReservationDetail.ReservationID)
            {
                return(BadRequest());
            }

            db.Entry(ReservationDetail).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ReservationDetailExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        private void ListItem_Click(object sender, EventArgs e)
        {
            Program            app = Program.GetInstance();
            ReservationService reservationService = app.GetService <ReservationService>("reservations");

            // Get the clicked item
            ListViewItem item = container.SelectedItems[0];

            if (item == null)
            {
                GuiHelper.ShowError("Geen item geselecteerd");
                return;
            }

            // Find the movie
            int         id          = (int)item.Tag;
            Reservation reservation = reservationService.GetReservationById(id);

            if (reservation == null)
            {
                GuiHelper.ShowError("Kon geen reservering vinden voor dit item");
                return;
            }

            // Show screen
            ReservationDetail reservationDetail = app.GetScreen <ReservationDetail>("reservationDetail");

            reservationDetail.SetReservation(reservation);
            app.ShowScreen(reservationDetail);
        }
Exemple #12
0
        public IActionResult AddDetailMessage(int id, string token, string message, bool ispublic)
        {
            DutyMember member = VerifyDutyMemberLogIn();

            if (member == null)
            {
                return(new JsonResult(new { result = false }));
            }

            if (VerifyDutyMemberDetailToken(member, id.ToString(), token) == false)
            {
                return(new JsonResult(new { result = false }));
            }

            ReservationDetail detail = (from d in db.ReservationDetails where d.Id == id select d).FirstOrDefault();

            if (detail == null)
            {
                return(new JsonResult(new { result = false }));
            }

            ReservationBoardMessage msg = new ReservationBoardMessage()
            {
                DutyMember        = member,
                Message           = message,
                PostedTime        = DateTimeHelper.GetBeijingTime(),
                ReservationDetail = detail,
                IsPublic          = ispublic
            };

            db.ReservationBoardMessages.Add(msg);
            db.SaveChanges();

            return(new JsonResult(new { result = true }));
        }
Exemple #13
0
 public void CreateReservationDetail(ReservationDetail reservationDetail)
 {
     try
     {
         _reservationDetailRepository.Add(reservationDetail);
     }
     catch { throw; }
 }
 public MaterialReservationDetailsView(ReservationDetail r, int amount, IReservationRepository reservationRepository)
 {
     this.StartReservation = r.Reservation.StartDate;
     this.EndReservation   = r.Reservation.EndDate;
     this.User             = r.Reservation.User;
     this.Amount           = amount;
     this.AmountAvailable  = reservationRepository.GetAmountOfAvailableIdentifiers(r.Reservation.StartDate,
                                                                                   r.Reservation.EndDate, r.MaterialIdentifier.Material);
 }
        private string EncryptDetailCredential(ReservationDetail detail)
        {
            Dictionary <string, string> option = new Dictionary <string, string>()
            {
                ["id"]    = detail.Id.ToString(),
                ["phone"] = detail.GetShortenPhone()
            };

            return(tokenservice.Encrypt(option));
        }
Exemple #16
0
        public DTO.ReservationDetail Execute(ReservationDetail reservationDetail)
        {
            var reservationDetailDto = TypeAdapter.Adapt <DTO.ReservationDetail>(reservationDetail);
            var reservation          = _reservationRepository.FindBy(reservationDetail.ReservationId);

            reservationDetailDto.Reservation = TypeAdapter.Adapt <DTO.Reservation>(reservation);
            var ingredient = _ingredientRepository.FindBy(reservationDetail.IngredientId);

            reservationDetailDto.Ingredient = TypeAdapter.Adapt <DTO.Ingredient>(ingredient);
            return(reservationDetailDto);
        }
        public IHttpActionResult GetReservationDetail(string id)
        {
            ReservationDetail reservationDetail = db.ReservationDetails.Find(id);

            if (reservationDetail == null)
            {
                return(NotFound());
            }

            return(Ok(reservationDetail));
        }
        public IActionResult ViewMessage(string id, string phone, int page = 1)
        {
            TempData["id"]    = id;
            TempData["phone"] = phone;
            TempData["page"]  = page;
            return(RedirectToActionPermanent(nameof(ViewMessage)));

            ReservationDetail _detail = VerifyReservationDetail(id, phone);

            if (_detail == null)
            {
                return(RedirectToAction(nameof(Index)));
            }
            db.Entry(_detail).EnsureReferencesLoaded(true);

            int total   = 1;
            int maxpage = 1;

            if (_detail.ReservationBoardMessages != null)
            {
                IEnumerable <ReservationBoardMessage> msgs = _detail.ReservationBoardMessages.Where(item => item.IsPublic == true);
                total   = msgs.Count();
                maxpage = (int)Math.Ceiling(total * 1.0 / ITEMS_PER_PAGE);
                if (maxpage <= 0)
                {
                    maxpage = 1;
                }
                if (page >= maxpage)
                {
                    page = maxpage;
                }
                page--;
                if (page < 0)
                {
                    page = 0;
                }
                msgs = msgs.OrderByDescending(item => item.PostedTime).Skip(page * ITEMS_PER_PAGE).Take(ITEMS_PER_PAGE);
                foreach (ReservationBoardMessage msg in msgs)
                {
                    db.Entry(msg).EnsureReferencesLoaded(false);
                }
                ViewData["Messages"] = msgs;
            }
            else
            {
                ViewData["Messages"] = new List <ReservationBoardMessage>();
                page = 0;
            }
            ViewData["Page"]    = page;
            ViewData["MaxPage"] = maxpage;
            ViewData["id"]      = id;
            ViewData["phone"]   = phone;
            return(View());
        }
        public async Task <IHttpActionResult> AddReservationDetails([FromBody] ReservationDetail reservationDetail)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.ReservationDetails.Add(reservationDetail);
            await db.SaveChangesAsync();

            return(CreatedAtRoute("DefaultApi", new { id = reservationDetail.IdReservationDetails }, reservationDetail));
        }
        public IActionResult Detail(string id, string phone)
        {
            phone = phone ?? "";
            ReservationDetail _detail = VerifyReservationDetail(id, phone);

            if (_detail == null)
            {
                return(RedirectToAction(nameof(Index)));
            }

            SetSessionTicket(id, phone);
            return(RedirectToActionPermanent(nameof(Detail)));
        }
Exemple #21
0
 // 用于向申请者发送短信
 // 通知已受理
 public Task SendAnsweredAsync(ReservationDetail reservation)
 {
     if (reservation.PosterPhone != null && reservation.PosterName != null)
     {
         string phone   = reservation.PosterPhone;
         string name    = reservation.PosterName;
         string message = "【北理网协】尊敬的" + name + "您好,您的电脑诊所预约已被受理,请按预约时间地点前往维修,若有变动请及时登录平台更改,谢谢。";
         return(SendSMSAsync(phone, message));
     }
     else
     {
         return(Task.CompletedTask);
     }
 }
Exemple #22
0
        public IActionResult CloseDetail(int id, string token)
        {
            DutyMember member = VerifyDutyMemberLogIn();

            if (member == null)
            {
                return(new JsonResult(new { result = false }));
            }

            if (VerifyDutyMemberDetailToken(member, id.ToString(), token) == false)
            {
                return(new JsonResult(new { result = false }));
            }

            ReservationDetail detail = (from d in db.ReservationDetails where d.Id == id select d).FirstOrDefault();

            if (detail == null)
            {
                return(new JsonResult(new { result = false }));
            }

            switch (detail.State)
            {
            case ReservationState.NewlyCreated:
                detail.State           = ReservationState.ClosedWithoutComplete;
                detail.ActionDate      = DateTimeHelper.GetBeijingTime();
                db.Entry(detail).State = EntityState.Modified;
                db.SaveChanges();
                break;

            case ReservationState.Answered:
            case ReservationState.Cancelled:
                if (member != detail.DutyMember)
                {
                    return(new JsonResult(new { result = false }));
                }

                detail.State           = ReservationState.ClosedWithoutComplete;
                detail.ActionDate      = DateTimeHelper.GetBeijingTime();
                db.Entry(detail).State = EntityState.Modified;
                db.SaveChanges();
                break;

            case ReservationState.Completed:
            case ReservationState.ClosedWithoutComplete:
            default:
                break;
            }
            return(new JsonResult(new { result = true }));
        }
Exemple #23
0
 public ReservationDetailViewModel(ReservationDetail detail)
 {
     if (detail.BroughtBackDate.HasValue)
     {
         BroughtBackDate = detail.BroughtBackDate.Value;
     }
     if (detail.PickUpDate.HasValue)
     {
         PickUpDate = detail.PickUpDate.Value;
     }
     Material           = new MaterialViewModel(detail.MaterialIdentifier.Material);
     MaterialIdentifier = detail.MaterialIdentifier;
     ReservationId      = detail.Reservation.Id;
 }
        public IActionResult SubmitModify(string id, string phone, string token, string postername, string posterphone, string posteremail, string posterqq, string posterschool, string problemtype, string problemdetail, string location, string bookdate)
        {
            ReservationDetail _detail = VerifyReservationDetailWithTicket(id, phone, token);

            if (_detail == null)
            {
                return(RedirectToAction(nameof(Index)));
            }

            DateTime _reservationDate;
            DateTime now = DateTimeHelper.GetBeijingTime();

            SchoolType   _schoolType   = (from school in db.SchoolTypes where school.Name == posterschool select school).FirstOrDefault();
            ProblemType  _problemType  = (from problem in db.ProblemTypes where problem.Name == problemtype select problem).FirstOrDefault();
            LocationType _locationType = (from loc in db.LocationTypes where loc.Name == location select loc).FirstOrDefault();

            string _postername  = postername ?? "";
            string _posterphone = posterphone ?? "";
            string _posteremail = posteremail ?? "";
            string _posterqq    = posterqq ?? "";

            if (_schoolType != null && _problemType != null && _locationType != null &&
                DateTime.TryParse(bookdate, out _reservationDate) == true)
            {
                _reservationDate            = new DateTime(_reservationDate.Year, _reservationDate.Month, _reservationDate.Day, 23, 59, 59);
                _detail.PosterName          = _postername;
                _detail.PosterPhone         = _posterphone;
                _detail.PosterEmail         = _posteremail;
                _detail.PosterQQ            = _posterqq;
                _detail.PosterSchoolType    = _schoolType;
                _detail.LocationType        = _locationType;
                _detail.ProblemType         = _problemType;
                _detail.Detail              = problemdetail;
                _detail.ModifiedDate        = now;
                _detail.LastUpdatedLanguage = cultureContext.Culture.Language;
                _detail.ReservationDate     = _reservationDate;
                EntityEntry <ReservationDetail> entry = db.Entry(_detail);
                entry.State = EntityState.Modified;
                db.SaveChanges();
                entry.Reload();
                smsService.SendReservationUpdatedAsync(entry.Entity);
                TempData["id"]    = entry.Entity.Id.ToString();
                TempData["phone"] = entry.Entity.GetShortenPhone();
                return(RedirectToActionPermanent(nameof(Detail)));
            }
            else
            {
            }
            return(View());
        }
Exemple #25
0
        private async Task AddReservationDetails(AddBookingVM vm)
        {
            var reservationDetails = new ReservationDetail
            {
                RoomReservationId = vm.RoomReservationId,
                RoomId            = vm.RoomId,
                CheckInDate       = vm.CheckInDate,
                CheckOutDate      = vm.CheckOutDate,
                Rate = _db.Rooms.Single(r => r.Id == vm.RoomId).Rate
            };

            _db.ReservationDetails.Add(reservationDetails);
            await _db.SaveChangesAsync();
        }
        public async Task <IHttpActionResult> RemoveReservationDetails(int id)
        {
            ReservationDetail reservationDetail = await db.ReservationDetails.FindAsync(id);

            if (reservationDetail == null)
            {
                return(NotFound());
            }

            db.ReservationDetails.Remove(reservationDetail);
            await db.SaveChangesAsync();

            return(Ok(reservationDetail));
        }
        public IHttpActionResult DeleteReservationDetail(string id)
        {
            ReservationDetail reservationDetail = db.ReservationDetails.Find(id);

            if (reservationDetail == null)
            {
                return(NotFound());
            }

            db.ReservationDetails.Remove(reservationDetail);
            db.SaveChanges();

            return(Ok(reservationDetail));
        }
        private ReservationDetail VerifyReservationDetail(string id, string phone)
        {
            int _id;

            if (int.TryParse(id, out _id) == false)
            {
                return(null);
            }

            ReservationDetail _detail = (from detail in db.ReservationDetails
                                         where (detail.Id == _id && ((detail.PosterPhone.Length == 0 && (phone == null || phone.Length == 0)) || (detail.PosterPhone.Length > 0 && phone != null && phone.Length > 0 && detail.PosterPhone.EndsWith(phone))))
                                         select detail).FirstOrDefault();

            return(_detail);
        }
Exemple #29
0
 // 用于向诊所人员发送短信
 // 当预约更改时通知受理该问题的人员
 public Task SendReservationUpdatedAsync(ReservationDetail reservation)
 {
     if (reservation.DutyMember != null)
     {
         string phone      = reservation.DutyMember.Contact;
         string postername = reservation.PosterName;
         int    ID         = reservation.Id;
         string message    = "【北理网协】您好,您受理的标识ID为" + ID + "的维修申请,已被用户" + postername + "作出更改,请及时登录平台查看。";
         return(SendSMSAsync(phone, message));
     }
     else
     {
         return(Task.CompletedTask);
     }
 }
Exemple #30
0
 // 用于向申请者发送短信
 // 通知创建申请成功
 public Task SendCreationSuccessAsync(ReservationDetail reservation, CultureExpression culture)
 {
     if (reservation.PosterPhone != null && reservation.PosterName != null)
     {
         string phone   = reservation.PosterPhone;
         string name    = reservation.PosterName;
         int    ID      = reservation.Id;
         string message = "【北理网协】尊敬的" + name + "您好,您的电脑诊所预约已成功,预约号(标识ID)为" + ID + ",请耐心等待维修人员受理,若有变动请及时登录平台更改,谢谢。";
         return(SendSMSAsync(phone, message));
     }
     else
     {
         return(Task.CompletedTask);
     }
 }