Пример #1
0
        public ActionResult Create([Bind(Include = "Id,FromPlace,DestinationPlace,StartDateTime,StartTime,EndDateTime,EndTime,Description,EmployeeId")] RequisitionViewModel requisitionViewModel)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var      startDate     = requisitionViewModel.StartDateTime.ToString("MM/dd/yyyy");
                    var      startTime     = requisitionViewModel.StartTime;
                    DateTime startDateTime = Convert.ToDateTime(startDate + " " + startTime);
                    requisitionViewModel.StartDateTime = startDateTime;

                    var      endDate     = requisitionViewModel.EndDateTime.ToString("MM/dd/yyyy");
                    var      endTime     = requisitionViewModel.EndTime;
                    DateTime endDateTime = Convert.ToDateTime(endDate + " " + endTime);
                    requisitionViewModel.EndDateTime = endDateTime;

                    requisitionViewModel.RequestFor        = "Own";
                    requisitionViewModel.RequisitionNumber = requisitionViewModel.GetRequisitionNumber();

                    Requisition requisition = Mapper.Map <Requisition>(requisitionViewModel);
                    bool        isSaved     = _requisitionManager.Add(requisition);

                    //Requisition Status Save
                    if (isSaved == true)
                    {
                        RequisitionStatus status = new RequisitionStatus();
                        status.RequisitionNumber = requisition.RequisitionNumber;

                        status.RequisitionId = requisition.Id;
                        status.StatusType    = "New";
                        _requisitionStatusManager.Add(status);
                        TempData["msg"] = "Requisition has been Send successfully....! Please Wait For Response..........Thanks";
                        return(RedirectToAction("Index"));
                    }
                }

                ViewBag.EmployeeId = new SelectList(_employeeManager.GetAll(), "Id", "FullName", requisitionViewModel.EmployeeId);
                return(View(requisitionViewModel));
            }
            catch (Exception ex)
            {
                return(View("", new HandleErrorInfo(ex, "Requisitions", "Create")));
            }
        }
Пример #2
0
        public ActionResult Create([Bind(Include = "Id,FromPlace,DestinationPlace,StartDateTime,StartTime,EndDateTime,EndTime,PassengerQty,Description,RequisitionType")] RequisitionViewModel requisitionViewModel)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var      startDate     = requisitionViewModel.StartDateTime.ToString("MM/dd/yyyy");
                    var      startTime     = requisitionViewModel.StartTime;
                    DateTime startDateTime = Convert.ToDateTime(startDate + " " + startTime);
                    requisitionViewModel.StartDateTime = startDateTime;

                    var      endDate     = requisitionViewModel.EndDateTime.ToString("MM/dd/yyyy");
                    var      endTime     = requisitionViewModel.EndTime;
                    DateTime endDateTime = Convert.ToDateTime(endDate + " " + endTime);
                    requisitionViewModel.EndDateTime = endDateTime;

                    requisitionViewModel.RequestFor        = "Own";
                    requisitionViewModel.RequisitionNumber = requisitionViewModel.GetRequisitionNumber();

                    //Get employee Id by user login id
                    var loginUserId = Convert.ToInt32(User.Identity.GetUserId());
                    var empId       = _employeeManager.FindByLoginId(loginUserId);
                    requisitionViewModel.EmployeeId = empId.Id;

                    Requisition requisition = Mapper.Map <Requisition>(requisitionViewModel);
                    requisition.SubmitDateTime = DateTime.Now;

                    bool isSaved = _requisitionManager.Add(requisition);

                    //Requisition Status Save
                    if (isSaved == true)
                    {
                        RequisitionStatus status = new RequisitionStatus();
                        status.RequisitionNumber = requisition.RequisitionNumber;

                        status.RequisitionId = requisition.Id;
                        status.StatusType    = "New";
                        _requisitionStatusManager.Add(status);

                        // Notification Status Save
                        Notification notification = new Notification();
                        notification.Text                 = "Request for a vehicle";
                        notification.EmployeeId           = empId.Id;
                        notification.ControllerViewStatus = "Unseen";
                        notification.RequisitionId        = requisition.Id;
                        notification.NotifyDateTime       = DateTime.Now;
                        _notificationManager.Add(notification);
                        TempData["msg"] = "Requisition has been Send successfully....! Please Wait For Response..........Thanks";
                        return(RedirectToAction("Create"));
                    }
                }

                ViewBag.EmployeeId = new SelectList(_employeeManager.GetAll(), "Id", "FullName", requisitionViewModel.EmployeeId);
                ICollection <Requisition>          requisitions          = _requisitionManager.GetAll();
                IEnumerable <RequisitionViewModel> requisitionViewModels =
                    Mapper.Map <IEnumerable <RequisitionViewModel> >(requisitions);
                ViewBag.Requisition = requisitionViewModels;

                //Get employee Id by user login id
                var loginUserId1 = Convert.ToInt32(User.Identity.GetUserId());
                var empId1       = _employeeManager.FindByLoginId(loginUserId1);

                //Notifications for assignd vehicle from controller
                var notification1     = _notificationManager.GetNotificationsForSender("Unseen", empId1.Id);
                var notificationCount = notification1.Count;

                if (notification1 != null)
                {
                    ViewBag.Notification = notification1;
                    ViewBag.count        = notificationCount;
                }

                ViewBag.Requisition = _requisitionManager.GetAllRequisitionByEmployeeId(empId1.Id);
                TempData["msg"]     = "Requisition send failed! You are missing to input proper value. Please check and try again!";

                return(View());
            }
            catch (Exception ex)
            {
                return(View("Error", new HandleErrorInfo(ex, "Requisitions", "Create")));
            }
        }