Beispiel #1
0
        public ActionResult CheckOut([Bind(Include = "Id,StatusType,RequisitionNumber,RequisitionId")] RequisitionStatusViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    RequisitionStatus requisitionStatus = Mapper.Map <RequisitionStatus>(model);
                    requisitionStatus.StatusType = "Completed";
                    bool IsSaved = _requisitionStatusManager.Update(requisitionStatus);
                    if (IsSaved)
                    {
                        RequisitionHistory history = new RequisitionHistory();
                        history.Status         = "Completed";
                        history.RequisitionId  = requisitionStatus.RequisitionId;
                        history.SubmitDateTime = DateTime.Now;
                        _requisitionHistoryManager.Add(history);
                    }
                    return(RedirectToAction("Index"));
                }


                return(View());
            }
            catch (Exception ex)
            {
                ExceptionMessage(ex);
                return(View("Error", new HandleErrorInfo(ex, "GatePass", "CheckOut")));
            }
        }
Beispiel #2
0
 public ActionResult DeleteConfirmed(int id)
 {
     try
     {
         Requisition requisition = _requisitionManager.FindById(id);
         bool        IsDeleted   = _requisitionManager.Remove(requisition);
         if (IsDeleted)
         {
             RequisitionHistory history = new RequisitionHistory();
             history.Status          = "New";
             history.RequisitionId   = requisition.Id;
             history.DeletedDateTime = DateTime.Now;
             _requisitionHistoryManager.Update(history);
         }
         TempData["msg"] = "Information has been deleted successfully";
         return(RedirectToAction("Index"));
     }
     catch (Exception ex)
     {
         ExceptionMessage(ex);
         return(View("Error", new HandleErrorInfo(ex, "Requisitions", "Delete")));
     }
 }
Beispiel #3
0
        //Hold Request Assign info get by requisitionId //Get

        private void SaveRequisition(AssignRequisitionViewModel assignRequisitionViewModel)
        {
            AssignRequisition assignRequisition = Mapper.Map <AssignRequisition>(assignRequisitionViewModel);
            bool isSave = _assignRequisitionManager.Add(assignRequisition);

            if (isSave)
            {
                //Requisition History Save
                RequisitionHistory history = new RequisitionHistory();
                history.Status         = "Assigned";
                history.RequisitionId  = assignRequisition.RequisitionId;
                history.SubmitDateTime = DateTime.Now;
                _requisitionHistoryManager.Add(history);

                //Requisition status information
                var status =
                    _requisitionStatusManager.FindByRequisitionId(assignRequisition.RequisitionId);
                status.Id                = assignRequisition.RequisitionStatusId;
                status.RequisitionId     = assignRequisition.RequisitionId;
                status.RequisitionNumber = assignRequisition.RequisitionNumber;
                status.StatusType        = "Assigned";

                bool Saved = _requisitionStatusManager.Update(status);

                if (Saved)
                {
                    //Notifaication status change after assign requisition
                    Notification notificationUpdate =
                        _notificationManager.FindByRequisitionId(assignRequisition.RequisitionId);

                    //Get Driver by id
                    var driver = _employeeManager.FindById(assignRequisition.EmployeeId);

                    //Get employee by requisition Id
                    var req = _requisitionManager.FindById(assignRequisition.RequisitionId);

                    if (notificationUpdate != null)
                    {
                        notificationUpdate.ControllerViewStatus = "Seen";
                        notificationUpdate.SenderViewStatus     = "Unseen";
                        notificationUpdate.SenderText           = "Your vehicle has been assigned";
                        notificationUpdate.SenderNotifyDateTime = DateTime.Now;
                        var updateResult = _notificationManager.Update(notificationUpdate);

                        //Sending mail to employee for assigned vehicle
                        if (updateResult)
                        {
                            //Get Vehicle Type by id
                            var vehicle = _vehicleManager.FindById(assignRequisition.VehicleId);

                            //Get controller info
                            var loginUserId = Convert.ToInt32(User.Identity.GetUserId());
                            var controller  = _employeeManager.FindByLoginId(loginUserId);

                            //Mail service section
                            var subject = "Assign a vehicle on your requisition no : " +
                                          assignRequisition.RequisitionNumber;

                            var msgBody = "Dear " + req.Employee.FullName + "," + Environment.NewLine +
                                          "On the basis of your request, assigned a vehicle." +
                                          Environment.NewLine + "Your driver is :" +
                                          driver.FullName + " Contect No : " + driver.ContactNo +
                                          Environment.NewLine + "Vehicle :" + vehicle.VehicleType.Name +
                                          " and Reg No : " + vehicle.RegNo + Environment.NewLine +
                                          "Regards, " + Environment.NewLine + controller.FullName;


                            MailService mailService = new MailService();
                            mailService.To                  = req.Employee.Email;
                            mailService.From                = "*****@*****.**";
                            mailService.Subject             = subject;
                            mailService.Body                = msgBody;
                            mailService.MailSendingDateTime = DateTime.Now;
                            mailService.RequisitionId       = req.Id;

                            var result = _mailServiceManager.Add(mailService);

                            if (result && req.Employee.Email != null)
                            {
                                SmtpClient smtpClient = new SmtpClient("smtp.gmail.com", 587);
                                smtpClient.Credentials =
                                    new NetworkCredential("*****@*****.**", "~Aa123456");
                                smtpClient.EnableSsl = true;


                                MailMessage mailMessage = new MailMessage();
                                mailMessage.From = new MailAddress("*****@*****.**");
                                mailMessage.To.Add(mailService.To);
                                mailMessage.Subject = mailService.Subject;
                                mailMessage.Body    = mailService.Body;
                                smtpClient.Send(mailMessage);

                                TempData["msg"] = "Vehicle assigned and mail send successfully";


                                //catch (Exception ex)
                                //{
                                //    TempData["msg1"] =
                                //        "Vehicle assigned and notification send successfully. Mail send failed. The error message is -" +
                                //        "<br/>" + " [ " + ex.Message + " Helpline" + " ] ";

                                //    return RedirectToAction("Index");
                                //}
                            }
                        }
                    }
                    try
                    {
                        //SmS to the driver and user

                        const string accountSid = "AC092d5f38c0ba5e8b384528c662c3209e";
                        const string authToken  = "a6bdd845a5552a4df57cc59c097223d1";
                        TwilioClient.Init(accountSid, authToken);
                        var to        = new PhoneNumber("+88" + driver.ContactNo);
                        var driverMsg = "Dear " + driver.FullName + "," + " You are assigned by the Requisition No " +
                                        req.RequisitionNumber + ", and Employee Contact Number is" +
                                        req.Employee.ContactNo;
                        var message = MessageResource.Create(
                            to,
                            from: new PhoneNumber("+18504035959"), //  From number, must be an SMS-enabled Twilio number ( This will send sms from ur "To" numbers ).
                            body: driverMsg);
                    }
                    catch (Exception ex)
                    {
                        var failMessage = ex.ToString();
                        TempData["msg"] = "Vehicle assigned and mail send successfully but fail to send message for invalid mobile number";
                    }
                }
            }
        }
Beispiel #4
0
        public ActionResult CreateRequestForOther([Bind(Include = "Id,FromPlace,DestinationPlace,StartDateTime,StartTime,EndDateTime,EndTime,PassengerQty,Description,RequisitionType,EmployeeId")] RequisitonForAnotherViewModel requisitonForAnother)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var      startDate     = requisitonForAnother.StartDateTime.ToString("MM/dd/yyyy");
                    var      startTime     = requisitonForAnother.StartTime;
                    DateTime startDateTime = Convert.ToDateTime(startDate + " " + startTime);
                    requisitonForAnother.StartDateTime = startDateTime;

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

                    if (requisitonForAnother.EmployeeId > 0)
                    {
                        var emp = _employeeManager.FindById(requisitonForAnother.EmployeeId);
                        requisitonForAnother.RequestFor = emp.FullName;
                    }

                    requisitonForAnother.RequisitionNumber = requisitonForAnother.GetRequisitionNumber();

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

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

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

                        status.RequisitionId = requisition.Id;
                        status.StatusType    = "New";
                        bool Saved = _requisitionStatusManager.Add(status);
                        if (Saved)
                        {
                            RequisitionHistory history = new RequisitionHistory();
                            history.Status         = "New";
                            history.RequisitionId  = requisition.Id;
                            history.SubmitDateTime = DateTime.Now;
                            _requisitionHistoryManager.Add(history);
                        }
                        // Notification Status Save
                        Notification notification = new Notification();
                        notification.RequisitionId            = requisition.Id;
                        notification.EmployeeId               = empId.Id;
                        notification.ControllerText           = "Request for a vehicle";
                        notification.ControllerViewStatus     = "Unseen";
                        notification.ControllerNotifyDateTime = DateTime.Now;
                        notification.SenderNotifyDateTime     = 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.GetAllEmployees(), "Id", "FullName", requisitonForAnother.EmployeeId);

                TempData["msg1"] = " Requisition send failed! You are missing to input proper value. Please check and try again! ";

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