예제 #1
0
        public ActionResult Edit(Permit permit, string searchString = "")
        {
            ViewBag.JSDatePattern = MvcApplication.JSDatePattern;
            ViewBag.SearchString  = searchString;

            if (ModelState.IsValid)
            {
                try
                {
                    repository.SavePermit(permit, permit.EmployeeID);
                }
                catch (DbUpdateConcurrencyException)
                {
                    return(Json(new { error = ModelError }));
                }

                Employee emp = repository.Employees.Where(e => e.EmployeeID == permit.EmployeeID).FirstOrDefault();
                if (permit.CancelRequestDate != null)
                {
                    Employee author            = repository.Employees.Where(e => e.EID == HttpContext.User.Identity.Name).FirstOrDefault();
                    Employee employeeForPermit = repository.Employees.Where(p => p.EmployeeID == permit.EmployeeID).FirstOrDefault();
                    messenger.Notify(new Message(MessageType.BTMCancelsPermitToADM, null, author, employeeForPermit));
                }
                List <Employee> empList = GetEmployeeData(repository.Employees.ToList(), searchString);
                return(View("TableViewVisasAndPermitsBTM", empList));
                //return RedirectToAction("BTMView", "Home", new { searchString = searchString });
            }

            PermitViewModel permitModel = new PermitViewModel(permit);

            return(View(permitModel));
        }
예제 #2
0
        public async Task <IOperationResult <PermitViewModel> > GetById(int permitId)
        {
            try
            {
                Permit permit = await _permitRepositoy.FindAsync(permit => permit.Id == permitId, permit => permit.PermitType);

                PermitViewModel permitsResult = await BuildPermit(permit);

                return(OperationResult <PermitViewModel> .Ok(permitsResult));
            }
            catch
            {
                return(OperationResult <PermitViewModel> .Fail("Ha ocurrido un error al cargar los permiso."));
            }
        }
예제 #3
0
        public void EditGet_CanEditSearchStringEmpty_ValidEmployeeID()
        {
            // Arrange - create the controller
            PermitController target = new PermitController(mock.Object, messengerMock.Object);

            MvcApplication.JSDatePattern = "dd.mm.yyyy";

            // Act - call the action method
            var             result = target.Edit(2) as ViewResult;
            PermitViewModel permit = (PermitViewModel)result.ViewData.Model;

            // Assert - check the result
            Assert.AreEqual("", result.ViewName);
            Assert.IsInstanceOf(typeof(ViewResult), result);
            Assert.AreEqual("dd.mm.yyyy", ((ViewResult)result).ViewBag.JSDatePAttern);
            Assert.IsNotNull(result.ViewData.Model);
            Assert.AreEqual(2, permit.EmployeeID);
            Assert.AreEqual("Struz Anatoliy (ascr) from TAAAA", result.ViewBag.EmployeeInformation);
        }
예제 #4
0
        //
        // GET: /Permit/Edit/5

        public ActionResult Edit(int id = 0, string searchString = "")
        {
            ViewBag.SearchString  = searchString;
            ViewBag.JSDatePattern = MvcApplication.JSDatePattern;
            Permit permit = (from p in repository.Permits where p.EmployeeID == id select p).FirstOrDefault();

            if (permit == null)
            {
                return(HttpNotFound());
            }
            else
            {
                ViewBag.EmployeeInformation = permit.PermitOf.LastName + " " + permit.PermitOf.FirstName + " (" + permit.PermitOf.EID + ") from " + permit.PermitOf.Department.DepartmentName;
                ViewBag.EmployeeID          = id;
                PermitViewModel permitModel = new PermitViewModel(permit);

                return(View(permitModel));
            }
        }
예제 #5
0
        public ActionResult Create(Permit permit, string searchString = "")
        {
            ViewBag.JSDatePattern = MvcApplication.JSDatePattern;
            ViewBag.SearchString  = searchString;

            if (ModelState.IsValid)
            {
                try
                {
                    repository.SavePermit(permit, permit.EmployeeID);
                }
                catch (System.InvalidOperationException)
                {
                    return(Json(new { error = ModelError }));
                }

                List <Employee> empList = GetEmployeeData(repository.Employees.ToList(), searchString);
                return(View("TableViewVisasAndPermitsBTM", empList));
            }

            PermitViewModel permitModel = new PermitViewModel(permit);

            return(View(permitModel));
        }
예제 #6
0
        /// <summary>
        /// Returns a PDF Permit
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public virtual IActionResult SchoolbusesIdPdfpermitGetAsync(int id)
        {
            FileContentResult result = null;
            bool exists = _context.SchoolBuss.Any(a => a.Id == id);

            if (exists)
            {
                SchoolBus schoolBus = _context.SchoolBuss
                                      .Include(x => x.CCWData)
                                      .Include(x => x.SchoolBusOwner.PrimaryContact)
                                      .Include(x => x.SchoolDistrict)
                                      .First(a => a.Id == id);

                // construct the view model.

                PermitViewModel permitViewModel = new PermitViewModel();

                // only do the ICBC fields if the CCW data is available.

                if (schoolBus.CCWData != null)
                {
                    permitViewModel.IcbcMake                    = schoolBus.CCWData.ICBCMake;
                    permitViewModel.IcbcModelYear               = schoolBus.CCWData.ICBCModelYear;
                    permitViewModel.IcbcRegistrationNumber      = schoolBus.CCWData.ICBCRegistrationNumber;
                    permitViewModel.VehicleIdentificationNumber = schoolBus.CCWData.ICBCVehicleIdentificationNumber;
                }
                permitViewModel.PermitIssueDate = null;
                if (schoolBus.PermitIssueDate != null)
                {
                    // Since the PDF template is raw HTML and won't convert a date object, we must adjust the time zone here.
                    TimeZoneInfo tzi = null;
                    try
                    {
                        // try the IANA timzeone first.
                        tzi = TimeZoneInfo.FindSystemTimeZoneById("America / Vancouver");
                    }
                    catch (Exception e)
                    {
                        tzi = null;
                    }

                    if (tzi == null)
                    {
                        try
                        {
                            tzi = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time");
                        }
                        catch (Exception e)
                        {
                            tzi = null;
                        }
                    }
                    DateTime dto = DateTime.UtcNow;
                    if (tzi != null)
                    {
                        dto = TimeZoneInfo.ConvertTime((DateTime)schoolBus.PermitIssueDate, tzi);
                    }
                    else
                    {
                        dto = (DateTime)schoolBus.PermitIssueDate;
                    }
                    permitViewModel.PermitIssueDate = dto.ToString("yyyy-MM-dd");
                }

                permitViewModel.PermitNumber     = schoolBus.PermitNumber;
                permitViewModel.RestrictionsText = schoolBus.RestrictionsText;

                if (schoolBus.SchoolBusOwner != null && schoolBus.SchoolBusOwner.PrimaryContact != null)
                {
                    permitViewModel.SchoolBusOwnerAddressLine1 = schoolBus.SchoolBusOwner.PrimaryContact.Address1;
                    permitViewModel.SchoolBusOwnerAddressLine2 = schoolBus.SchoolBusOwner.PrimaryContact.Address2;
                    permitViewModel.SchoolBusOwnerName         = schoolBus.SchoolBusOwner.Name;
                }
                permitViewModel.SchoolBusSeatingCapacity = schoolBus.SchoolBusSeatingCapacity;
                if (schoolBus.SchoolDistrict != null)
                {
                    permitViewModel.SchoolDistrictshortName = schoolBus.SchoolDistrict.ShortName;
                }
                string payload = JsonConvert.SerializeObject(permitViewModel);

                // pass the request on to the PDF Micro Service
                string pdfHost = Configuration["PDF_SERVICE_NAME"];

                string targetUrl = pdfHost + "/api/PDF/GetPDF";

                // call the microservice
                try
                {
                    HttpClient client = new HttpClient();

                    var request = new HttpRequestMessage(HttpMethod.Post, targetUrl);
                    request.Content = new StringContent(payload, Encoding.UTF8, "application/json");

                    request.Headers.Clear();
                    // transfer over the request headers.
                    foreach (var item in Request.Headers)
                    {
                        string key   = item.Key;
                        string value = item.Value;
                        request.Headers.Add(key, value);
                    }

                    Task <HttpResponseMessage> responseTask = client.SendAsync(request);
                    responseTask.Wait();

                    HttpResponseMessage response = responseTask.Result;
                    if (response.StatusCode == HttpStatusCode.OK) // success
                    {
                        var bytetask = response.Content.ReadAsByteArrayAsync();
                        bytetask.Wait();

                        result = new FileContentResult(bytetask.Result, "application/pdf");
                        result.FileDownloadName = "Permit-" + schoolBus.PermitNumber + ".pdf";
                    }
                }
                catch (Exception e)
                {
                    result = null;
                }

                // check that the result has a value
                if (result != null)
                {
                    return(result);
                }
                else
                {
                    return(new StatusCodeResult(400)); // problem occured
                }
            }
            else
            {
                // record not found
                return(new StatusCodeResult(404));
            }
        }
예제 #7
0
        /// <summary>
        /// Returns a PDF Permit
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public virtual IActionResult SchoolbusesIdPdfpermitGetAsync(int id)
        {
            FileContentResult result = null;
            bool exists = _context.SchoolBuss.Any(a => a.Id == id);

            if (exists)
            {
                SchoolBus schoolBus = _context.SchoolBuss
                                      .Include(x => x.CCWData)
                                      .Include(x => x.SchoolBusOwner.PrimaryContact)
                                      .Include(x => x.SchoolDistrict)
                                      .First(a => a.Id == id);

                // construct the view model.

                PermitViewModel permitViewModel = new PermitViewModel();

                // only do the ICBC fields if the CCW data is available.

                if (schoolBus.CCWData != null)
                {
                    permitViewModel.IcbcMake                    = schoolBus.CCWData.ICBCMake;
                    permitViewModel.IcbcModelYear               = schoolBus.CCWData.ICBCModelYear;
                    permitViewModel.IcbcRegistrationNumber      = schoolBus.CCWData.ICBCRegistrationNumber;
                    permitViewModel.VehicleIdentificationNumber = schoolBus.CCWData.ICBCVehicleIdentificationNumber;

                    permitViewModel.SchoolBusOwnerAddressLine1 = schoolBus.CCWData.ICBCRegOwnerAddr1;

                    // line 2 is a combination of the various fields that may contain data.
                    List <string> strings = new List <string>();
                    if (!string.IsNullOrWhiteSpace(schoolBus.CCWData.ICBCRegOwnerAddr2))
                    {
                        strings.Add(schoolBus.CCWData.ICBCRegOwnerAddr2);
                    }
                    if (!string.IsNullOrWhiteSpace(schoolBus.CCWData.ICBCRegOwnerCity))
                    {
                        strings.Add(schoolBus.CCWData.ICBCRegOwnerCity);
                    }
                    if (!string.IsNullOrWhiteSpace(schoolBus.CCWData.ICBCRegOwnerProv))
                    {
                        strings.Add(schoolBus.CCWData.ICBCRegOwnerProv);
                    }
                    if (!string.IsNullOrWhiteSpace(schoolBus.CCWData.ICBCRegOwnerPostalCode))
                    {
                        strings.Add(schoolBus.CCWData.ICBCRegOwnerPostalCode);
                    }
                    if (strings.Count > 0)
                    {
                        permitViewModel.SchoolBusOwnerAddressLine2 = String.Join(", ", strings);
                    }

                    permitViewModel.SchoolBusOwnerPostalCode = schoolBus.CCWData.ICBCRegOwnerPostalCode;
                    permitViewModel.SchoolBusOwnerProvince   = schoolBus.CCWData.ICBCRegOwnerProv;
                    permitViewModel.SchoolBusOwnerCity       = schoolBus.CCWData.ICBCRegOwnerCity;
                    permitViewModel.SchoolBusOwnerName       = schoolBus.CCWData.ICBCRegOwnerName;
                }

                permitViewModel.PermitIssueDate = schoolBus.PermitIssueDate == null ?
                                                  null : ConvertUtcToPacificTime((DateTime)schoolBus.PermitIssueDate).ToString("yyyy-MM-dd");

                permitViewModel.PermitNumber                 = schoolBus.PermitNumber;
                permitViewModel.RestrictionsText             = schoolBus.RestrictionsText;
                permitViewModel.SchoolBusMobilityAidCapacity = schoolBus.MobilityAidCapacity.ToString();
                permitViewModel.UnitNumber               = schoolBus.UnitNumber;
                permitViewModel.PermitClassCode          = schoolBus.PermitClassCode;
                permitViewModel.BodyTypeCode             = schoolBus.BodyTypeCode;
                permitViewModel.SchoolBusSeatingCapacity = schoolBus.SchoolBusSeatingCapacity;

                if (schoolBus.SchoolDistrict != null)
                {
                    permitViewModel.SchoolDistrictshortName = schoolBus.SchoolDistrict.ShortName;
                }

                string payload = JsonConvert.SerializeObject(permitViewModel);

                // pass the request on to the PDF Micro Service
                string pdfHost = Configuration["PDF_SERVICE_NAME"];

                string targetUrl = pdfHost + "/api/PDF/GetPDF";

                // call the microservice

                HttpClient client = new HttpClient();
                try
                {
                    var request = new HttpRequestMessage(HttpMethod.Post, targetUrl);
                    request.Content = new StringContent(payload, Encoding.UTF8, "application/json");

                    request.Headers.Clear();
                    // transfer over the request headers.
                    foreach (var item in Request.Headers)
                    {
                        string key   = item.Key;
                        string value = item.Value;
                        request.Headers.Add(key, value);
                    }

                    Task <HttpResponseMessage> responseTask = client.SendAsync(request);
                    responseTask.Wait();
                    HttpResponseMessage response = responseTask.Result;
                    if (response.StatusCode == HttpStatusCode.OK) // success
                    {
                        var bytetask = response.Content.ReadAsByteArrayAsync();
                        bytetask.Wait();
                        result = new FileContentResult(bytetask.Result, "application/pdf");
                        result.FileDownloadName = "Permit-" + schoolBus.PermitNumber + ".pdf";
                    }
                }
                catch (Exception e)
                {
                    result = null;
                    Console.WriteLine(e.ToString());
                }

                finally
                {
                    if (client != null)
                    {
                        try
                        {
                            client.Dispose();
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e.ToString());
                        }
                    }
                }

                // check that the result has a value
                if (result != null)
                {
                    return(result);
                }
                else
                {
                    return(new StatusCodeResult(503));
                }
            }
            else
            {
                // record not found
                return(new StatusCodeResult(404));
            }
        }