private void btnReservationAdd_Click(object sender, EventArgs e)
        {
            status = DateTime.Compare(DateTime.Now, dteDateIn.DateTime.Date);
            Guest guest = GuestControl();

            try
            {
                if (guest == null)
                {
                    _guestService.Add(new Guest
                    {
                        FirstName = txbGuestName.Text,
                        LastName  = txbGuestLastName.Text,
                        TCIdNo    = txbTCIdNo.Text
                    });
                }
                GuestControl();

                _reservationService.Add(new Reservation
                {
                    GuestId = guest.Id,
                    RoomId  = Convert.ToInt32(dgwEmptyRooms.SelectedRows[0].Cells[0].Value),
                    DateIn  = dteDateIn.DateTime.Date,
                    DateOut = dteDateOut.DateTime.Date,
                    Status  = status
                });
                MessageBox.Show("Kayıt Yapıldı");
                this.Close();
            }
            catch (Exception)
            {
                MessageBox.Show("Kayıt Başarısız");
            }
            this.Close();
        }
Esempio n. 2
0
        public IActionResult Post([FromBody] ReservationModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    model.Id = _reservationService.Add(model);

                    if (!model.Id.Equals(Guid.Empty))
                    {
                        return(Created(string.Empty, model));
                    }
                    else
                    {
                        return(NoContent());
                    }
                }
                else
                {
                    return(BadRequest(ModelState));
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError(string.Empty, ex.Message);
                return(BadRequest(ModelState));
            }
        }
Esempio n. 3
0
        public IHttpActionResult Reserv(ReservModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Invalid data"));
            }

            var    quest = questService.GetAll().Where(x => x.Id == model.QuestId).FirstOrDefault();
            double cost  = quest.Price;

            if (!String.IsNullOrEmpty(model.Code))
            {
                if (reservationService.VerifyCertificateCode(model.Code))
                {
                    cost = 0;
                }
                else
                {
                    return(BadRequest("Invalid code"));
                }
            }

            reservationService.Add(new ReservDTO {
                Quest = quest, DateTimeSections = model.Date + " " + model.Time, Cost = cost
            });
            return(Ok($"Quest \"{quest.Name}\" reserved for {model.Date} on {model.Time}\nCost: {cost} grn"));
        }
Esempio n. 4
0
        public ActionResult Add(Models.Reservation.AddViewModel model)
        {
            if (!ModelState.IsValid)
            {
                model.CustomerSelectList = GetCustomerSelectList();
                return(View(model));
            }
            var reservation = _reservationService.GetRoomByRoomIdWithDetail(model.RoomId);

            if (reservation.IsEmpty == false)
            {
                return(View("_ErrorNotExist"));
            }

            Reservation record = new Reservation();

            record.CustomerId      = model.CustomerId;
            record.RoomId          = reservation.RoomId;
            record.CreatedDateTime = DateTime.Now;
            record.EntryDate       = DateTime.Now;
            var result = _reservationService.Add(record);

            if (result > 0)
            {
                return(RedirectToAction(nameof(ReservationController.List)));
            }
            else
            {
                ViewBag.ErrorMessage     = "Not Saved";
                model.CustomerSelectList = GetCustomerSelectList();
                return(View(model));
            }
        }
Esempio n. 5
0
 public void Post([FromBody] Reservation reservation)
 {
     if (ModelState.IsValid)
     {
         _reservationService.Add(reservation);
     }
 }
 public async Task CreateReservation(List <Reservation> reservations)
 {
     foreach (var reservation in reservations)
     {
         await _service.Add(reservation);
     }
 }
Esempio n. 7
0
 public ActionResult AddReservation(ReservationModel model)
 {
     if (model.CheckIn < DateTime.Now.AddDays(-1) || model.CheckIn > model.CheckOut)
     {
         return(Json("Hata"));
     }
     _reservationService.Add(model);
     return(Json("Başarılı"));
 }
Esempio n. 8
0
        public IActionResult Add(Reservation reservation)
        {
            var result = reservationManager.Add(reservation);

            if (result.Success)
            {
                return(Ok(result));
            }
            return(BadRequest(result));
        }
Esempio n. 9
0
        public ActionResult StudentReservation(Reservation res)
        {
            string resultstr = "err";
            //先查询是否已经有预约信息,如果没有被预约,再插入
            List <Reservation> temp = reservationService.GetEntities(u => u.Delflag == (int)DelflagEnum.Normal && u.ComputerinfoID == res.ComputerinfoID && u.Sdate == res.Sdate && u.DateFlag == res.DateFlag).ToList();

            if (temp.Count() == 0)
            {
                res.Rdate   = DateTime.Now;
                res.Edate   = res.Sdate;
                res.Status  = (int)StatusEnum.Normal;
                res.Delflag = (int)DelflagEnum.Normal;
                //从缓存里面拿到userLoginId信息
                string   userLoginId = Request.Cookies["userLoginId"].Value.ToString();
                Userinfo userInfo    = CacheHelper.GetCache(userLoginId) as Userinfo;
                res.UserinfoID = userInfo.ID;
                reservationService.Add(res);
                resultstr = "ok";
            }

            return(Json(resultstr));
        }
Esempio n. 10
0
        public HttpResponseMessage Post(ReservationCrateViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(new HttpResponseMessage(HttpStatusCode.BadRequest));
            }
            Reservation item = Mapper.Map <ReservationCrateViewModel, Reservation>(model);


            _reservationService.Add(item);
            _db.SaveChanges();
            return(new HttpResponseMessage(HttpStatusCode.OK));
        }
Esempio n. 11
0
        public ActionResult Create(reservation r)
        {//debut code khawla
            IUserService service   = new UserService();
            user         u         = service.GetById(User.Identity.GetUserId());
            string       firstName = u.firstName;
            string       lastName  = u.lastName;
            string       email     = u.Email;

            ViewBag.userFirstName = firstName;
            ViewBag.userLastName  = lastName;
            ViewBag.userMail      = email;
            ViewBag.sexe          = u.sexe.ToLower();
            //fin code khawla

            int id = int.Parse(this.RouteData.Values["id"].ToString());

            r.reservationState = 1;
            r.flight_idFlight  = 1;
            ause.Add(r);
            return(RedirectToAction("Index"));
        }
Esempio n. 12
0
        private void btnConfirmReserv_Click(object sender, EventArgs e)
        {
            if (cboxTimeSelector.SelectedIndex < 0)
            {
                MessageBox.Show("Please select time");
                return;
            }

            DateTime date = clndrDateSelector.SelectionRange.Start;
            DateTime time = DateTime.Parse(cboxTimeSelector.SelectedItem.ToString());
            double   cost = quest.Price;
            string   code = txtBoxsertifacateCode.Text.Trim().ToUpper();

            if (ckBoxHasSertificate.Checked == true)
            {
                if (!String.IsNullOrEmpty(code))
                {
                    if (rs.VerifyCertificateCode(code))
                    {
                        cost = 0;
                    }
                    else
                    {
                        MessageBox.Show("Invalid code");
                        return;
                    }
                }
                else
                {
                    MessageBox.Show("Enter code");
                    return;
                }
            }

            rs.Add(new ReservDTO {
                Quest = quest, DateTimeSections = date.ToShortDateString() + " " + time.ToShortTimeString(), Cost = cost
            });
            MessageBox.Show($"Quest \"{quest.Name}\" reserved for {date.ToShortDateString()} on {time.ToShortTimeString()}\nCost: {cost} grn");
            this.Close();
        }
        private void AddClicked(object sender, RoutedEventArgs e)
        {
            if (isValidValues())
            {
                var  users = userService.FindEmail(userEmail.Text);
                user user;
                if (!users.Any())
                {
                    user = userService.Create(userEmail.Text);
                }
                else
                {
                    user = users.First();
                }

                var res = reservationService.CreateReservation(startDate.SelectedDate.Value.Date, endDate.SelectedDate.Value.Date,
                                                               user.id, (int)roomsList.SelectedItem);
                reservationService.Add(res);

                this.Close();
            }
        }
Esempio n. 14
0
        public async Task <IActionResult> Add([FromBody] ReservationAddDto reservationDto)
        {
            reservationDto.DateOfReservation = reservationDto.DateOfReservation.Date;

            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var userId = GetUserId();

            if (userId == null)
            {
                return(BadRequest());
            }

            var user = await _userService.GetById(userId);

            if (user == null)
            {
                return(BadRequest());
            }

            var res = _mapper.Map <Reservation>(reservationDto);

            res.UserStringId = user.StringId;

            var reservation = await _reservationService.Add(res);

            if (reservation == null)
            {
                return(BadRequest());
            }

            return(Ok());
        }
Esempio n. 15
0
        public ActionResult Create([Bind(Include = "Start,End,Email,Beds,Quality")] ReservationModel res)
        {
            if (ModelState.IsValid)
            {
                var availableRooms = roomService.FindAvailable(res.Start, res.End);
                var vacant         = availableRooms.Find(room => room.beds == res.Beds && room.quality.ToLower() == res.Quality.ToLower());

                var user = userService.CreateIfAbsent(res.Email);

                if (vacant != null)
                {
                    reservation reservation = reservationService.CreateReservation(res.Start, res.End, user.id, vacant.id);
                    reservationService.Add(reservation);

                    return(RedirectToAction("Index"));
                }
                else
                {
                    ViewBag.NotVacant = "No rooms that satisfy your needs are available at this moment.";
                }
            }

            return(View(res));
        }
        // POST api/<controller>
        public ReservationDTO Post([FromBody] ReservationDTO dto)
        {
            ReservationDTO retVal = reservationService.Add(dto);

            return(retVal);
        }
Esempio n. 17
0
        public JsonResult SaveReservation(ReservationModel model, int action)
        {
            try {
                if (model == null)
                {
                    throw new ArgumentException("model");
                }
                var startTime = DateTime.Parse(model.expStartDate);
                var endTime   = DateTime.Parse(model.endDate);
                var interval  = endTime.Subtract(startTime);
                if (interval.TotalSeconds < 0)
                {
                    throw new iPemException("预约结束时间不能早于预约开始时间");
                }
                //if (interval.TotalSeconds > 86400) throw new iPemException("预约总时长不能超过24个小时");
                if (model.nodes == null || model.nodes.Length == 0)
                {
                    throw new iPemException("未选择需要预约的监控节点");
                }

                var project = _projectService.GetProject(model.projectId);
                if (project == null)
                {
                    throw new iPemException("未找到所关联的工程信息");
                }
                if (!(project.StartTime <= startTime && project.EndTime > endTime))
                {
                    throw new iPemException("预约时间已超出关联的工程时间");
                }

                if (action == (int)EnmAction.Add)
                {
                    var newOne = new M_Reservation {
                        Id           = model.id,
                        Name         = model.name,
                        ExpStartTime = startTime,
                        EndTime      = endTime,
                        ProjectId    = project.Id,
                        Creator      = _workContext.Employee() != null?_workContext.Employee().Name : _workContext.User().Uid,
                        UserId       = _workContext.User().Id,
                        CreatedTime  = DateTime.Now,
                        Comment      = model.comment,
                        Enabled      = model.enabled,
                        Status       = EnmResult.Undefine
                    };

                    var nodes = new List <M_NodeInReservation>();
                    foreach (var node in model.nodes)
                    {
                        var keys = Common.SplitKeys(node);
                        if (keys.Length == 2)
                        {
                            var type = int.Parse(keys[0]);
                            nodes.Add(new M_NodeInReservation {
                                ReservationId = newOne.Id,
                                NodeId        = keys[1],
                                NodeType      = Enum.IsDefined(typeof(EnmSSH), type) ? (EnmSSH)type : EnmSSH.Area
                            });
                        }
                    }

                    _reservationService.Add(newOne);
                    _nodesInReservationService.Add(nodes.ToArray());
                    _webLogger.Information(EnmEventType.Other, string.Format("新增预约[{0}]", newOne.Id), _workContext.User().Id, null);
                    return(Json(new AjaxResultModel {
                        success = true, code = 200, message = "保存成功"
                    }));
                }
                else if (action == (int)EnmAction.Edit)
                {
                    var existed = _reservationService.GetReservation(model.id);
                    if (existed == null)
                    {
                        throw new iPemException("预约不存在,保存失败。");
                    }
                    if (existed.Creator != (_workContext.Employee() != null ? _workContext.Employee().Name : _workContext.User().Uid))
                    {
                        throw new iPemException("您没有操作权限。");
                    }

                    existed.Name         = model.name;
                    existed.ExpStartTime = startTime;
                    existed.EndTime      = endTime;
                    existed.ProjectId    = project.Id;
                    existed.Comment      = model.comment;
                    existed.Enabled      = model.enabled;
                    existed.Status       = EnmResult.Undefine;

                    var nodes = new List <M_NodeInReservation>();
                    foreach (var node in model.nodes)
                    {
                        var keys = Common.SplitKeys(node);
                        if (keys.Length == 2)
                        {
                            var type = int.Parse(keys[0]);
                            nodes.Add(new M_NodeInReservation {
                                ReservationId = existed.Id,
                                NodeId        = keys[1],
                                NodeType      = Enum.IsDefined(typeof(EnmSSH), type) ? (EnmSSH)type : EnmSSH.Area
                            });
                        }
                    }

                    _reservationService.Update(existed);
                    _nodesInReservationService.Remove(existed.Id);
                    _nodesInReservationService.Add(nodes.ToArray());
                    _webLogger.Information(EnmEventType.Other, string.Format("更新预约[{0}]", model.id), _workContext.User().Id, null);
                    return(Json(new AjaxResultModel {
                        success = true, code = 200, message = "保存成功"
                    }));
                }

                throw new ArgumentException("action");
            } catch (Exception exc) {
                _webLogger.Error(EnmEventType.Other, exc.Message, _workContext.User().Id, exc);
                return(Json(new AjaxResultModel {
                    success = false, code = 400, message = exc.Message
                }));
            }
        }
        public async Task <ActionResult> Create(ReservationViewModel reservationIn)
        {
            var userId = User.Claims.Where(claim => claim.Type == JwtRegisteredClaimNames.Sid).FirstOrDefault().Value;

            if (ModelState.IsValid)
            {
                try
                {
                    if (string.IsNullOrWhiteSpace(reservationIn.CronoExpression))
                    {
                        var reservation = new Reservation
                        {
                            Start            = reservationIn.Start,
                            End              = reservationIn.End,
                            ResourceId       = reservationIn.ResourceId,
                            UserId           = userId,
                            Title            = reservationIn.Title,
                            PeriodicId       = string.Empty,
                            ResourceType     = reservationIn.ResourceType,
                            ResourceTypeName = reservationIn.ResourceTypeName,
                            ResourceName     = reservationIn.ResourceName
                        };
                        await _reservationService.Add(reservation);

                        return(CreatedAtRoute("GetReservation", new { id = reservation.ToString() }, reservation));
                    }
                    else
                    {
                        var expression  = CronExpression.Parse(reservationIn.CronoExpression);
                        var occurrences = expression.GetOccurrences(
                            reservationIn.Start,
                            reservationIn.End,
                            fromInclusive: true,
                            toInclusive: true);
                        if (occurrences == null)
                        {
                            return(null);
                        }
                        var reservations = new List <Reservation>();
                        var periodicId   = Guid.NewGuid().ToString();
                        foreach (var startTime in occurrences)
                        {
                            var endTime = new DateTime(startTime.Year, startTime.Month, startTime.Day, reservationIn.End.Hour, reservationIn.End.Minute, 0);
                            reservations.Add(new Reservation
                            {
                                Start            = startTime,
                                End              = endTime,
                                ResourceId       = reservationIn.ResourceId,
                                UserId           = userId,
                                Title            = reservationIn.Title,
                                PeriodicId       = periodicId,
                                ResourceType     = reservationIn.ResourceType,
                                StartRecur       = new DateTime(reservationIn.Start.Year, reservationIn.Start.Month, reservationIn.Start.Day, 0, 0, 0),
                                StartTime        = new DateTime(reservationIn.Start.Year, reservationIn.Start.Month, reservationIn.Start.Day, reservationIn.Start.Hour, reservationIn.Start.Minute, 0),
                                EndRecur         = new DateTime(reservationIn.End.Year, reservationIn.End.Month, reservationIn.End.Day, 0, 0, 0),
                                EndTime          = new DateTime(reservationIn.End.Year, reservationIn.End.Month, reservationIn.End.Day, reservationIn.End.Hour, reservationIn.End.Minute, 0),
                                WeekDays         = reservationIn.WeekDays,
                                ResourceTypeName = reservationIn.ResourceTypeName,
                                ResourceName     = reservationIn.ResourceName
                            }
                                             );
                        }
                        await _reservationService.Add(reservations);

                        return(CreatedAtRoute("GetPeriodicReservations", new { id = periodicId }, reservations));
                    }
                }
                catch (ReservationServiceException ex)
                {
                    foreach (var field in ex.Fields)
                    {
                        ModelState.AddModelError(field, ex.Message);
                    }
                    return(BadRequest(new ValidationProblemDetails(ModelState)));
                }
                catch (Exception ex)
                {
                    var test = ex.GetType();
                    return(StatusCode(500, "Internal server error"));
                }
            }
            return(BadRequest(new ValidationProblemDetails(ModelState)));
        }
Esempio n. 19
0
 public void Add_TryToCreateNullValue_ShouldThrowException()
 {
     // act & assert
     Assert.Throws <ArgumentNullException>(() => reservationService.Add(null));
 }
Esempio n. 20
0
 public IActionResult AddReservation(Reservation reservation)
 {
     reservationService.Add(reservation);
     return(RedirectToAction("Index"));
 }