예제 #1
0
        public ActionResult Create(MeetingAdminViewModel meeting)
        {
            meeting.DayOfBooking = DateTime.Now;
            meeting.UserName     = User.Identity.Name;

            bool isAllowed = true;

            ViewBag.Error = "";

            if (!_mdb.isAllow(meeting.MeetingRoomId, meeting.BeginTime, meeting.EndTime))
            {
                isAllowed     = false;
                ViewBag.Error = "Комната занята в это время";
            }

            if (ModelState.IsValid && isAllowed)
            {
                Meeting a = Mapper.Map <MeetingAdminViewModel, Meeting>(meeting);
                _mdb.Add(a);
                return(RedirectToAction("Index"));
            }

            ViewBag.MeetingRoomId = new SelectList(_mrdb.GetAllRooms(), "Id", "Name", meeting.MeetingRoomId);

            return(View(meeting));
        }
예제 #2
0
        // POST: api/MeetingRoomApi
        public string Post(MeetingAddViewModel meeting)
        {
            if (!_udb.Login(meeting.UserName, meeting.Password))
            {
                return("Ошибка входа");
            }

            try
            {
                Meeting meetingToSave = Mapper.Map <MeetingAddViewModel, Meeting>(meeting);
                meetingToSave.DayOfBooking  = DateTime.Now;
                meetingToSave.UserName      = meeting.UserName;
                meetingToSave.Status        = Meeting.StatusTypes.Waiting;
                meetingToSave.MeetingRoomId = meeting.MeetingRoomId;
                if (_mdb.isAllow(meeting.MeetingRoomId, meeting.BeginTime, meeting.EndTime))
                {
                    meetingToSave.Price = (int)(meeting.EndTime - meeting.BeginTime).TotalHours * 100;
                    _mdb.Add(meetingToSave);
                    return("ok");
                }
                else
                {
                    throw new Exception("Команата занята или даты некорректны");
                }
            }
            catch (Exception exc)
            {
                return(exc.InnerException.Message);
            }
        }