예제 #1
0
        public ActionResult Create([Bind(Include = "Id,To,Subject,Body")] MailServiceViewModel mailServiceViewModel)
        {
            if (ModelState.IsValid)
            {
                MailService mailService = Mapper.Map <MailService>(mailServiceViewModel);
                mailService.MailSendingDateTime = DateTime.Now;
                mailService.From = "*****@*****.**";
                var result = _mailServiceManager.Add(mailService);
                if (result)
                {
                    try
                    {
                        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"] = "Mail has been save and send successfully";
                        return(RedirectToAction("Index"));
                    }
                    catch (Exception ex)
                    {
                        TempData["msg1"] = "Mail sending failed. The error message is -" + "<br/>" + " [ " + ex.Message + " Helpline" + " ] ";

                        return(RedirectToAction("Index"));
                    }
                }

                //ViewBag.RequisitionId = new SelectList(_requisitionManager.GetAllWithEmployee(), "Id", "RequisitionNumber", mailServiceViewModel.RequisitionId);
                return(View(mailServiceViewModel));
            }

            ViewBag.RequisitionId = new SelectList(_requisitionManager.GetAllWithEmployee(), "Id", "RequisitionNumber", mailServiceViewModel.RequisitionId);
            return(View(mailServiceViewModel));
        }
        public ActionResult Create([Bind(Include = "Id,RequisitionId,RequisitionStatusId,RequisitionNumber,VehicleId,EmployeeId")] AssignRequisitionViewModel assignRequisitionViewModel)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    AssignRequisition assignRequisition = Mapper.Map <AssignRequisition>(assignRequisitionViewModel);
                    bool isSave = _assignRequisitionManager.Add(assignRequisition);

                    if (isSave)
                    {
                        //Requisition status information
                        RequisitionStatus status = new RequisitionStatus();
                        status.Id                = assignRequisition.RequisitionStatusId;
                        status.RequisitionId     = assignRequisition.RequisitionId;
                        status.RequisitionNumber = assignRequisition.RequisitionNumber;
                        status.StatusType        = "Assigned";
                        _requisitionStatusManager.Update(status);



                        //Controller status change after assign requisition
                        Notification notificationUpdate = _notificationManager.FindByRequisitionId(assignRequisition.RequisitionId);
                        notificationUpdate.ControllerViewStatus = "Seen";
                        _notificationManager.Update(notificationUpdate);


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

                        //Get Driver by id
                        var driver = _employeeManager.FindById(assignRequisition.EmployeeId);
                        //Get Vehicle Type by id
                        var vehicle = _vehicleManager.FindById(assignRequisition.VehicleId);

                        //Assigned vehicle notification for employee by Controlle
                        Notification notification = new Notification();
                        notification.Text             = "Your vehicle has been assigned";
                        notification.EmployeeId       = employee.Id;
                        notification.RequisitionId    = assignRequisition.RequisitionId;
                        notification.SenderViewStatus = "Unseen";
                        notification.NotifyDateTime   = DateTime.Now;
                        _notificationManager.Add(notification);

                        //Sending mail to employee for assigned vehicle
                        var loginUserId = Convert.ToInt32(User.Identity.GetUserId());
                        var controller  = _employeeManager.FindByLoginId(loginUserId);

                        if (employee.Email != null)
                        {
                            var subject = "Assign a vehicle on your requisition no : " + assignRequisition.RequisitionNumber;
                            var msgBody = "Dear " + employee.FullName + "," + " \n\r " + " \r\r\r\r\r\r " + " On the basis of your request, assigned a vehicle. Your driver is " +
                                          driver.FullName + " Contect No : " + driver.ContactNo + ". Vehicle " + vehicle.VehicleType.Name +
                                          " and Reg No : " + vehicle.RegNo + ". " + " \n\r " + "Regards, " + " \n " + " \r\r\r\r\r\r " + controller.FullName;

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

                            var result = _mailServiceManager.Add(mailService);

                            if (result)
                            {
                                try
                                {
                                    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";
                                    return(RedirectToAction("PrintDetails", "AssignRequisitions", new { id = assignRequisition.Id }));
                                }
                                catch (Exception ex)
                                {
                                    TempData["msg1"] = "Vehicle assigned but mail send failed. The error message is -" + "<br/>" + " [ " + ex.Message + " Helpline" + " ] ";

                                    return(RedirectToAction("Index"));
                                }
                            }
                        }
                        return(RedirectToAction("Index"));
                    }
                }

                Requisition requisition = _requisitionManager.FindById(assignRequisitionViewModel.RequisitionId);

                RequisitionViewModel requisitionViewModel = Mapper.Map <RequisitionViewModel>(ViewBag.Requisition = requisition);
                assignRequisitionViewModel.RequisitionId = assignRequisitionViewModel.RequisitionId;
                assignRequisitionViewModel.VehicleTypes  = _vehicleTypeManager.GetAll().ToList();


                ViewBag.RequisitionNumber = assignRequisitionViewModel.RequisitionNumber;
                ViewBag.EmployeeId        = new SelectList(_employeeManager.GetAllDriver(), "Id", "FullName");
                ViewBag.VehicleId         = new SelectListItem[] { new SelectListItem()
                                                                   {
                                                                       Value = "", Text = "Select Vehicle"
                                                                   } };
                ViewBag.RequisitionStatusId = new SelectList(_requisitionStatusManager.GetAllStatusNew(), "Id", "StatusType");


                TempData["msg"] = "Assign faield! You have missed to select all field.";

                return(View(assignRequisitionViewModel));
            }
            catch (Exception ex)
            {
                return(View("Error", new HandleErrorInfo(ex, "AssignRequisitions", "Create")));
            }
        }
예제 #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";
                    }
                }
            }
        }