public RequestModel(CreateRequestViewModel request) { Id = request.Id; UserId = request.UserId; DriverId = request.DriverId; Status = request.Status; PickupAddress = new Address { UserId = request.UserId, StreetNumber = request.PickupStreetName, StreetName = request.PickupStreetName, City = request.PickupCity, State = request.PickupState, ZipCode = request.PickupZipcode }; DropOffAddress = new Address { UserId = request.UserId, StreetNumber = request.DropoffStreetName, StreetName = request.DropoffStreetName, City = request.DropoffCity, State = request.DropoffState, ZipCode = request.DropoffZipcode }; Item = request.Item; PickUpInstructions = request.PickupInstructions; DropOffInstructions = request.DropoffInstructions; ImageName = request.ImageName; }
private void CheckModelValues(CreateRequestViewModel expected, CreateRequestViewModel actual) { Assert.Equal(expected.Id, actual.Id); Assert.Equal(expected.PickupStreetNumber, actual.PickupStreetNumber); Assert.Equal(expected.PickupStreetName, actual.PickupStreetName); Assert.Equal(expected.PickupCity, actual.PickupCity); Assert.Equal(expected.PickupState, actual.PickupState); Assert.Equal(expected.PickupZipcode, actual.PickupZipcode); Assert.Equal(expected.DropoffStreetNumber, actual.DropoffStreetNumber); Assert.Equal(expected.DropoffStreetName, actual.DropoffStreetName); Assert.Equal(expected.DropoffCity, actual.DropoffCity); Assert.Equal(expected.DropoffZipcode, actual.DropoffZipcode); Assert.Equal(expected.Item, actual.Item); }
public void UpdatePickupAddress(CreateRequestViewModel model, RequestModel request) { var address = new Address { UserId = request.UserId, StreetNumber = model.PickupStreetNumber, StreetName = model.PickupStreetName, City = model.PickupCity, State = model.PickupState, ZipCode = model.PickupZipcode }; if (_context.IfExistingAddress(address)) { request.PickupAddressId = _context.GetAddressId(address); } else { request.PickupAddress = new Identity.Address { UserId = request.UserId, StreetNumber = model.PickupStreetNumber, StreetName = model.PickupStreetName, City = model.PickupCity, State = model.PickupState, ZipCode = model.PickupZipcode }; } }
public int CreateNewRequest(CreateRequestViewModel requestVm) { var request = Mapper.Map <Request>(requestVm); request.Status = StatusEnum.InProgress; return(_requestRepository.Add(request)); }
public void UpdateDropoffAddress(CreateRequestViewModel model, RequestModel request) { var address = new Address { UserId = request.UserId, StreetNumber = model.DropoffStreetNumber, StreetName = model.DropoffStreetName, City = model.DropoffCity, State = model.DropoffState, ZipCode = model.DropoffZipcode }; if (_context.IfExistingAddress(address)) { request.DropOffAddressId = _context.GetAddressId(address); } else { request.DropOffAddress = new Address { UserId = request.UserId, StreetNumber = model.DropoffStreetNumber, StreetName = model.DropoffStreetName, City = model.DropoffCity, State = model.DropoffState, ZipCode = model.DropoffZipcode }; } }
public async Task <IActionResult> CreateRequest(CreateRequestViewModel model) { if (ModelState.IsValid) { var user = await _userManager.FindByNameAsync(User?.Identity?.Name); if (user != null) { var result = await _requestService.CreateNewRequestAsync(user.Id, user.UserName, model.Topic, model.Message, !model.PublicRequest); if (result.IsFaulted) { ModelState.AddModelError(string.Empty, result.Messages.FirstOrDefault()); } else { //TODO - here whould be redirect to user requests page. return(RedirectToAction("Index", "Home")); } } ModelState.AddModelError(string.Empty, ApplicationResources.UserInterface.Common.UserDoNotExist); } return(View(model)); }
public void CreateRequestTest() { var createRequestViewModel = new CreateRequestViewModel() { CityId = 1, CompanyName = "HP", CreatedBy = 1, CustomerAddress = "b/1 test appartment", CustomerContact = "0", CustomerName = "Test User", Expense = 10000, ModelNumber = "Envy 15", PinCode = "380011", ProblemDetails = "My laptop is not working", StateId = 1 }; //Modal state fail test var response = repairRequestController.CreateRequest(createRequestViewModel); Assert.IsInstanceOfType(response, typeof(BadRequestResult)); createRequestViewModel.CustomerContact = "9737669480"; //Try after entering all valid values response = repairRequestController.CreateRequest(createRequestViewModel); Assert.IsInstanceOfType(response, typeof(OkResult)); }
public IActionResult CreateRequest(CreateRequestViewModel vm) { // Check it's valid if (vm.SelectedType == "Choose Request Type" || string.IsNullOrEmpty(vm.Reason)) { return(RedirectToAction("CreateRequest")); } // Create a new admin request var newReq = new AdminRequests(); newReq.RequestDescription = vm.Reason; newReq.SentByUserId = _context.Users.First(u => u.UserName == HttpContext.Session.GetString("Username")).UserId; newReq.Responded = false; newReq.DateRequested = DateTime.Now; newReq.RequestTypeId = _context.RequestTypes.First(r => r.RequestName == vm.SelectedType).RequestTypeId; // Add it to database _context.AdminRequests.Add(newReq); // Save database _context.SaveChanges(); // Redirect to dashboard return(Redirect("~/Project/Dashboard")); }
public void Update_Success(int id) { var contextMock = new Mock <IDbContext>(); var hostingEnv = new Mock <IHostingEnvironment>(); var requestMock = MockRequestModel(); var modelMock = new CreateRequestViewModel(requestMock); var user = new ClaimsPrincipal(new ClaimsIdentity(new Claim[] { new Claim(ClaimTypes.NameIdentifier, "1") })); var controller = new RequestController(contextMock.Object, hostingEnv.Object) { ControllerContext = new ControllerContext() { HttpContext = new DefaultHttpContext() { User = user } } }; contextMock.Setup(x => x.GetRequestById(id)).Returns(requestMock); contextMock.Setup(x => x.GetUserAddresses(It.IsAny <string>())) .Returns(new List <Address> { MockAddress() }); var response = controller.Update(id); var result = response as ViewResult; Assert.IsType <ViewResult>(response); CheckModelValues(modelMock, result.Model as CreateRequestViewModel); }
public void Open_Success() { var contextMock = new Mock <IDbContext>(); var hostingEnv = new Mock <IHostingEnvironment>(); var requestMock = MockRequestModel(); var modelMock = new CreateRequestViewModel(requestMock); var user = new ClaimsPrincipal(new ClaimsIdentity(new Claim[] { new Claim(ClaimTypes.NameIdentifier, "1") })); var controller = new RequestController(contextMock.Object) { ControllerContext = new ControllerContext() { HttpContext = new DefaultHttpContext() { User = user } } }; contextMock.Setup(x => x.GetRequests()) .Returns(new List <RequestModel> { requestMock }); contextMock.Setup(x => x.UpdateRequest(It.IsAny <RequestModel>())); var response = controller.Open(); var result = response as ViewResult; Assert.IsType <ViewResult>(response); //Assert.Equal(1, (result.Model as List<CreateRequestViewModel>).Count); }
public ActionResult Index([Bind(Include = "OriginId,ServiceId,Category1Id,Category2Id,Category3Id,Category4Id,ImpactId,Contact,Title,Description")] CreateRequestViewModel createRequestViewModel) { if (ModelState.IsValid) { return(RedirectToAction("Create", createRequestViewModel)); } return(View("Index", createRequestViewModel)); }
public CreateRequestPage(Data.Model.CarService cs) { InitializeComponent(); BindingContext = model = new CreateRequestViewModel(); csModel = cs; }
// Create a new request view public IActionResult CreateRequest() { var vm = new CreateRequestViewModel(); // Create new view model vm.RequestType = _context.RequestTypes.Where(r => r.RequestTypeId > -1).Select(r => r.RequestName).ToList(); // Get the request type from the database // Return the view return(View(vm)); }
public async Task <IActionResult> CreatePost(CreateRequestViewModel model) { if (!ModelState.IsValid) { return(View(model)); } await _service.CreateRequestAsync(model.ToModel()); return(RedirectToAction("Index")); }
public async Task <Application> UpdateAsync(CreateRequestViewModel vm, Application application) { application.Name = vm.Name; application.Description = vm.Description; application.HomepageUrl = vm.HomepageUrl; application.RedirectUrl = vm.RedirectUrl; _context.Applications.Update(application); await _context.SaveChangesAsync(); return(application); }
public async Task <IActionResult> Create(CreateRequestViewModel model) { if (!this.ModelState.IsValid) { return(this.View("Create", model)); } model.RequestedById = this.usersService.GetUserIdByUser(this.User); await this.requestsService.AddRequestAsync(model); return(this.RedirectToAction("My")); }
public IActionResult UpdateStatus(int id) { RequestModel request = _context.GetRequestById(id); // TODO: return a view instead of contenet if (request == null) { return(Content("Request with given id does not exist.")); } CreateRequestViewModel requestVM = new CreateRequestViewModel(request); return(View(requestVM)); }
public IActionResult Pickup(int id) { RequestModel request = _context.GetRequestById(id); if (request == null) { //TODO: Dont return content return(Content("Request with given id does not exist.")); } CreateRequestViewModel requestVM = new CreateRequestViewModel(request); return(View(requestVM)); }
public IActionResult UpdateStatus(CreateRequestViewModel model) { RequestModel request = _context.GetRequestById(model.Id); var status = model.Status; var newStatus = status; if (status == "Accepted By Driver") { newStatus = "Awaiting Pickup"; } else if (status == "Awaiting Pickup") { newStatus = "Out for Delivery"; } else if (status == "Out for Delivery") { newStatus = "Delivered"; var subject = "Request for " + model.Item + " has been delivered"; var message = "Your order has been successfully delivered"; new Mailer().SendMail(subject, _context.GetUser(model.UserId).Email, message); subject = "Request for " + model.Item + " has been delivered"; message = "You have successfully delivered the request"; new Mailer().SendMail(subject, _context.GetUser(model.DriverId).Email, message); } request.UserId = model.UserId; request.DriverId = model.DriverId; request.Status = newStatus; request.PickupAddress.StreetNumber = model.PickupStreetNumber; request.PickupAddress.StreetName = model.PickupStreetName; request.PickupAddress.City = model.PickupCity; request.PickupAddress.State = model.PickupState; request.PickupAddress.ZipCode = model.PickupZipcode; request.DropOffAddress.StreetNumber = model.DropoffStreetNumber; request.DropOffAddress.StreetName = model.DropoffStreetName; request.DropOffAddress.City = model.DropoffCity; request.DropOffAddress.State = model.DropoffState; request.DropOffAddress.ZipCode = model.DropoffZipcode; request.Item = model.Item; request.PickUpInstructions = model.PickupInstructions; request.DropOffInstructions = model.DropoffInstructions; _context.UpdateRequest(request); return(RedirectToAction("AcceptedRequests")); }
public void Detail_Success(int id) { var contextMock = new Mock <IDbContext>(); var hostingEnv = new Mock <IHostingEnvironment>(); var controller = new RequestController(contextMock.Object, hostingEnv.Object); var requestMock = MockRequestModel(); var modelMock = new CreateRequestViewModel(requestMock); contextMock.Setup(x => x.GetRequestById(id)) .Returns(requestMock); var response = controller.Detail(id); var result = (response as ViewResult); Assert.IsType <ViewResult>(response); CheckModelValues(modelMock, result.Model as CreateRequestViewModel); }
public void PickupRequest_Success() { var contextMock = new Mock <IDbContext>(); var hostingEnv = new Mock <IHostingEnvironment>(); var controller = new RequestController(contextMock.Object); var requestMock = MockRequestModel(); var modelMock = new CreateRequestViewModel(requestMock); contextMock.Setup(x => x.GetRequestById(It.IsAny <int>())) .Returns(requestMock); contextMock.Setup(x => x.UpdateRequest(It.IsAny <RequestModel>())); var response = controller.UpdateStatus(modelMock); contextMock.Verify(x => x.UpdateRequest(It.IsAny <RequestModel>()), Times.Once()); Assert.IsType <RedirectToActionResult>(response); }
public async Task <IActionResult> Update([FromBody] CreateRequestViewModel vm, Guid id) { if (!ModelState.IsValid) { return(new JsonResult(new { status = 400, message = "Validation failed", data = ModelState }) { StatusCode = StatusCodes.Status400BadRequest }); } User user = (User)HttpContext.Items["User"]; Application application = await _applicationService.FindAsync(id); if (application == null || application.AuthorId != user.Id) { return(new JsonResult(new { status = 400, message = "Invalid application id provided", }) { StatusCode = StatusCodes.Status400BadRequest }); } application = await _applicationService.UpdateAsync(vm, application); ApplicationViewModel appVm = application.ToViewModel(); return(new JsonResult(new { status = 200, message = "Application updated successfully", data = new { application = appVm } })); }
private string FirstVideoUploadedFile(CreateRequestViewModel model) { string firstVideoFileName = null; if (model.Video != null) { string uploadsfolder = Path.Combine(hostingEnvironment.WebRootPath, "videos"); firstVideoFileName = Guid.NewGuid().ToString() + " _" + model.Video.FileName; string filePath = Path.Combine(uploadsfolder, firstVideoFileName); using (var fileStream = new FileStream(filePath, FileMode.Create)) { model.Video.CopyTo(fileStream); } } return(firstVideoFileName); }
public async Task AddRequestAsync(CreateRequestViewModel viewModel) { var user = this.usersService.GetUserById(viewModel.RequestedById); var request = new Request() { Name = viewModel.Name, Type = (ProductType)Enum.Parse(typeof(ProductType), viewModel.Type), Status = RequestStatus.Pending, Description = viewModel.Description, RequestedById = viewModel.RequestedById, RequestedBy = user, RequestedOn = DateTime.UtcNow, MoneyCreationPrice = viewModel.MoneyCreationPrice, DeeCoinsCreationPrice = viewModel.DeeCoinsCreationPrice, }; var images = await this.imagesService.UploadRequestImagesAsync(viewModel.Images, request); }
public void UpdateDatabase_Success() { var contextMock = new Mock <IDbContext>(); var hostingEnv = new Mock <IHostingEnvironment>(); var controller = new RequestController(contextMock.Object, hostingEnv.Object); var requestMock = MockRequestModel(); var modelMock = new CreateRequestViewModel(requestMock); var addressMock = MockAddress(); contextMock.Setup(x => x.GetRequestById(modelMock.Id)) .Returns(requestMock); contextMock.Setup(x => x.UpdateRequest(It.IsAny <RequestModel>())); contextMock.Setup(x => x.IfExistingAddress(It.IsAny <Address>())) .Returns(true); var response = controller.Update(modelMock); Assert.IsType <RedirectToActionResult>(response); }
public IActionResult Create(CreateRequestViewModel model) { RequestModel request = new RequestModel { UserId = User.FindFirstValue(ClaimTypes.NameIdentifier), Status = "Awaiting Driver", Item = model.Item, PickUpInstructions = model.PickupInstructions, DropOffInstructions = model.DropoffInstructions, ImageName = Upload(model.Image) }; UpdatePickupAddress(model, request); UpdateDropoffAddress(model, request); // add to the context _context.AddRequest(request); return(RedirectToAction("ConfirmUpdate", new CreateRequestViewModel(request))); }
public IActionResult Create(CreateRequestViewModel viewModel) { if (ModelState.IsValid) { var model = new Request { Id = 0, Name = viewModel.Name, Description = viewModel.Description, RequestCreated = DateTime.Now, UserId = userManager.GetUserId(HttpContext.User), RequestStatusId = 1 // Want to set the status to received, should be seeded with its id as 1. }; repository.SaveRequest(model); return(RedirectToAction("Index")); } return(View(viewModel)); }
public IActionResult PickupRequest(CreateRequestViewModel model) { RequestModel request = _context.GetRequestById(model.Id); request.DriverId = User.FindFirstValue(ClaimTypes.NameIdentifier); request.Status = "Accepted By Driver"; var driver = _context.GetUser(request.DriverId); _context.UpdateRequest(request); //get user from ID for mail fields var subject = "Request for " + model.Item + " has been accepted"; var message = "Your order has been accepted by " + driver.UserName + ". \nThe driver will arrive in a " + driver.CarColor + " " + driver.CarYear + " " + driver.CarMake + " " + driver.CarModel + ". You can contact the driver at " + driver.Email + " or by phone at " + driver.PhoneNumber + "."; new Mailer().SendMail(subject, _context.GetUser(model.UserId).Email, message); return(RedirectToAction("ConfirmPickup")); }
public IActionResult Update(int id) { RequestModel request = _context.GetRequestById(id); if (request == null) { return(Content("Request with given id does not exist.")); } CreateRequestViewModel requestVM = new CreateRequestViewModel(request); var addresses = _context .GetUserAddresses(User.FindFirstValue(ClaimTypes.NameIdentifier)); Address[] addressArray = addresses.ToArray(); ViewBag.AddressList = GetAddressList(); ViewData["AddressArray"] = addressArray; return(View(requestVM)); }
public async Task <Application> CreateAsync(CreateRequestViewModel vm, User user) { Application application = new Application { Name = vm.Name, Description = vm.Description, AuthorId = user.Id, Author = user, HomepageUrl = vm.HomepageUrl, RedirectUrl = vm.RedirectUrl, ClientId = Guid.NewGuid(), ClientSecret = _randomValueService.CryptoSafeRandomString(), FirstParty = false }; await _context.AddAsync(application); await _context.SaveChangesAsync(); return(application); }