public async Task TestUpdateService() { var newServiceInputModel = new ServiceInputModel { Name = "test", Description = "Lorem Ipsum is simply dummy text of the printing and typesetting industry.", HeadImage = this.file, Document = this.document, }; var id = await this.servicesService.CreateServiceAsync(newServiceInputModel); var newServiceInputModelForUpdate = new ServiceInputModel { Id = id, Name = "test update", Description = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Update", HeadImage = this.file, Document = this.document, }; await this.servicesService.UpdateServiceAsync(newServiceInputModelForUpdate); var service = await this.servicesService.GetServiceByIdForViewAsync(id); Assert.Equal("test update", service.Name); }
public async Task <int> CreateServiceAsync(ServiceInputModel input) { var headImageId = await this.filesService.UploadToFileSystemAsync(input.HeadImage, "images\\serviceImages", "Service Hade Image"); string documentId = null; if (input.Document != null) { documentId = await this.filesService.UploadToFileSystemAsync(input.Document, "documents\\service\\official", "Service " + input.Name + " document"); } var newService = new Service { Name = input.Name, Description = input.Description, HeadImageId = headImageId, DocumentId = documentId, }; await this.dbService.AddAsync(newService); await this.dbService.SaveChangesAsync(); return(newService.Id); }
public async Task UpdateServiceAsync(ServiceInputModel input) { var currentService = this.dbService.All().FirstOrDefault(s => s.Id == input.Id); if (input.HeadImage != null) { var headImageId = await this.filesService.UploadToFileSystemAsync(input.HeadImage, "images\\serviceImages", "Service Hade Image"); currentService.HeadImageId = headImageId; } if (input.Document != null) { var documentId = await this.filesService.UploadToFileSystemAsync(input.Document, "documents\\service\\official", "Service " + input.Name + "document"); currentService.DocumentId = documentId; } if (currentService.Name != input.Name) { currentService.Name = input.Name; } if (currentService.Description != input.Description) { currentService.Description = input.Description; } this.dbService.Update(currentService); await this.dbService.SaveChangesAsync(); }
public async Task <IActionResult> Edit(ServiceInputModel model) { if (!this.servicesService.Exists(model.Id)) { return(this.BadRequest()); } if (!ModelState.IsValid) { return(this.RedirectToAction("Error", "Home")); } EditServiceServiceModel serviceModel = new EditServiceServiceModel { Id = model.Id, Name = model.ServiceName, Price = model.Price, Description = model.ServiceDescription, IsShownInSubMenu = model.IsShownInSubMenu, ServiceTypeId = model.ServiceTypeId, VehicleTypeId = model.VehicleTypeId, OperatingLocationIds = (model.OperatingLocationIds == null) ? new int[0] : model.OperatingLocationIds, DocumentIds = (model.DocumentIds == null) ? new int[0] : model.DocumentIds, }; await this.servicesService.EditAsync(serviceModel); return(this.RedirectToAction("Details", "Services", new { id = serviceModel.Id })); }
public async Task EditAsync(int id, ServiceInputModel model) { var editedService = this.repository.AllWithDeleted().FirstOrDefault(x => x.Id == id); editedService.Name = model.Name; editedService.Description = model.Description; await this.repository.SaveChangesAsync(); }
public async Task <IActionResult> UpdateService(ServiceInputModel input) { if (!this.ModelState.IsValid) { return(this.View(input)); } await this.servicesService.UpdateServiceAsync(input); return(this.RedirectToAction("Index")); }
public async Task <IActionResult> AddService(ServiceInputModel input) { if (!this.ModelState.IsValid) { return(this.View(input)); } await this.service.CreateAsync(input); this.TempData["Message"] = "Service was added successfully"; return(this.RedirectToAction(nameof(this.Index))); }
public async Task CreateAsync(ServiceInputModel input) { var newService = new Service { Name = input.Name, Description = input.Description, }; await this.repository.AddAsync(newService); await this.repository.SaveChangesAsync(); }
public async Task TestCreateProject() { var newServiceInputModel = new ServiceInputModel { Name = "test", Description = "Lorem Ipsum is simply dummy text of the printing and typesetting industry.", HeadImage = this.file, Document = this.document, }; var id = await this.servicesService.CreateServiceAsync(newServiceInputModel); Assert.True(id > 0); }
public IActionResult Edit(int id) { ServiceServiceModel service = this.servicesService.GetById(id); if (service.Name == null) { return(this.BadRequest()); } var model = new ServiceInputModel { Id = service.Id, ServiceName = service.Name, IsShownInSubMenu = service.IsShownInSubMenu, ServiceDescription = service.Description, Price = service.Price, VehicleTypeId = service.VehicleTypeId, VehicleTypes = this.vehicleTypesService.GetAll().Select(x => new VehicleTypesDropdownViewModel { Id = x.Id, Name = x.Name, Category = x.Category, }), ServiceTypeId = service.ServiceTypeId, ServiceTypes = this.serviceTypesService.GetAll().Select(x => new ServiceTypesDropdownViewModel { Id = x.Id, Name = x.Name, }), OperatingLocationIds = service.OperatingLocationIds, OperatingLocations = this.operatingLocationsService.GetAll().Select(x => new OperatingLocationsDropdownViewModel { Id = x.Id, Town = x.Town, Address = x.Address, }), DocumentIds = service.DocumentIds, Documents = this.documentsService.GetAll().Select(x => new DocumentsDropdownViewModel { Id = x.Id, Name = x.Name, }), }; return(this.View(model)); }
public async Task <IActionResult> Create(ServiceInputModel model) { this.FillServiceUnifiedModel(); if (!this.ModelState.IsValid) { return(this.View("Create", this.unifiedModel)); } var operatingLocations = new List <OperatingLocationsDropdownServiceModel>(); if (model.OperatingLocationIds != null) { foreach (int operatingLocationId in model.OperatingLocationIds) { operatingLocations.Add(new OperatingLocationsDropdownServiceModel { Id = operatingLocationId, }); } } var documents = new List <DocumentsDropdownServiceModel>(); if (model.DocumentIds != null) { foreach (int documentId in model.DocumentIds) { documents.Add(new DocumentsDropdownServiceModel { Id = documentId, }); } } var service = new CreateServiceServiceModel { ServiceTypeId = model.ServiceTypeId, VehicleTypeId = model.VehicleTypeId, ServiceName = model.ServiceName, ServiceDescription = model.ServiceDescription, IsShownInSubMenu = model.IsShownInSubMenu, Price = model.Price, OperatingLocations = operatingLocations, Documents = documents, }; await this.servicesService.CreateAsync(service); return(this.RedirectToAction("Create")); }
public async Task <IActionResult> Edit(int id, ServiceInputModel input) { if (!this.ModelState.IsValid) { return(this.View(input)); } await this.service.EditAsync(id, input); var viewModel = this.service.GetServiceById(id); this.TempData["Message"] = "Service was edited successfully"; return(this.RedirectToAction(nameof(this.ManageServices))); }
public async Task TestGetAllService() { var newServiceInputModel = new ServiceInputModel { Name = "test", Description = "Lorem Ipsum is simply dummy text of the printing and typesetting industry.", HeadImage = this.file, Document = this.document, }; var idOne = await this.servicesService.CreateServiceAsync(newServiceInputModel); var idTwo = await this.servicesService.CreateServiceAsync(newServiceInputModel); var allServices = this.servicesService.GetAllService().ToList(); }
public async Task <IActionResult> AddService(ServiceInputModel input) { if (!this.ModelState.IsValid) { return(this.View(input)); } // Add Service var serviceId = await this.servicesService.AddAsync(input.Name, input.CategoryId, input.Description); // Add the Service to all Partners in the Category var partnersIds = await this.partnersService.GetAllIdsByCategoryAsync(input.CategoryId); await this.partnerServicesService.AddAsync(partnersIds, serviceId); return(this.RedirectToAction("Index")); }
public async Task TestDeleteDocument() { var newServiceInputModel = new ServiceInputModel { Name = "test", Description = "Lorem Ipsum is simply dummy text of the printing and typesetting industry.", HeadImage = this.file, Document = this.document, }; var id = await this.servicesService.CreateServiceAsync(newServiceInputModel); await this.servicesService.DeleteDocumentAsync(id); var service = await this.servicesService.GetServiceByIdAsync(id); Assert.Null(service.DocumentId); }
public async Task TestChangeIsDeleteService() { var newServiceInputModel = new ServiceInputModel { Name = "test", Description = "Lorem Ipsum is simply dummy text of the printing and typesetting industry.", HeadImage = this.file, Document = this.document, }; var id = await this.servicesService.CreateServiceAsync(newServiceInputModel); await this.servicesService.ChangeIsDeleteServiceAsync(id); var service = this.serviceRepository.AllWithDeleted().FirstOrDefault(); Assert.True(service.IsDeleted); }
public async Task TestGetAllServiceWithDeleted() { var newServiceInputModel = new ServiceInputModel { Name = "test", Description = "Lorem Ipsum is simply dummy text of the printing and typesetting industry.", HeadImage = this.file, Document = this.document, }; var idOne = await this.servicesService.CreateServiceAsync(newServiceInputModel); var idTwo = await this.servicesService.CreateServiceAsync(newServiceInputModel); await this.servicesService.ChangeIsDeleteServiceAsync(idOne); var services = this.serviceRepository.AllWithDeleted(); Assert.Equal(2, services.ToList().Count); }
public async Task <ActionResult <ServiceViewModel> > PostService([FromBody] ServiceInputModel serviceModel) { Service service = _mapper.Map <Service>(serviceModel); _servicesRepository.Insert(service); try { await _unitWork.SaveAsync(); } catch (DbUpdateException) { if (ServiceExists(service.Code)) { return(Conflict($"Ya existe un servicio con el código {serviceModel.Code}.")); } throw; } return(_mapper.Map <ServiceViewModel>(service)); }