public IActionResult CreateService(CreateServiceViewModel model, List <IFormFile> images) { if (!User.Identity.IsAuthenticated) { return(RedirectToAction("Login", "Login")); } if (!ModelState.IsValid) { if (model.Category == "Select a category") { ModelState.AddModelError("Category", "Select a category"); } return(View()); } var currentUserId = _userLogic.GetUserByEmail(User.Identity.Name).Id; _offeredServiceLogic.CreateService(model.Name, model.Category, model.DeliveryTimeDays, model.DeliveryTimeHours, model.Description, model.Price, currentUserId); if (images != null && images.Count > 0) { _imageLogic.UploadImages(images, currentUserId); } TempData["ServiceIsCreated"] = true; var myCreatedServiceId = _offeredServiceLogic.GetLatestOfferedServiceIdByProviderId(currentUserId); return(RedirectToAction("MyOfferedService", "Profile", new { myOfferedServiceId = myCreatedServiceId })); }
public IActionResult CreateService(CreateServiceViewModel model) { if (!ModelState.IsValid) { return(View(model)); } Service service = new Service() { Id = Guid.NewGuid(), Description = model.Description, ServiceType = model.ServiceType, Price = model.Price, Vehicle = model.Vehicle, CreatedAt = DateTime.UtcNow, UpdatedAt = DateTime.UtcNow, }; this._context.Services.Add(service); this._context.SaveChanges(); return(RedirectToAction("Index")); }
public IActionResult Index(long serviceId) { var model = new CreateServiceViewModel(); if (serviceId == 0) { model.Id = "0"; } else // init edit form { model.Id = serviceId.ToString(); var service = _context.Services.Where(c => c.Id == serviceId).FirstOrDefault(); model.Name = service.Name; model.Price = service.Price.ToString(); model.ImageUrl = service.ImageUrl; model.Description = service.Description; model.Duration = service.Duration; model.CategoryId = service.CategoryId.ToString(); } model.Categories = _context.Category.Select(c => new SelectListItem { Value = c.CategoryId.ToString(), Text = c.Name }); return(View(model)); }
public async Task <SystemSucceededTask> CreateService(CreateServiceViewModel model, string userName) { var newService = new Service { Active = model.Active, DatabaseSystem = _systemRepository.GetById(model.DatabaseSystemId), Hostname = model.Hostname, Ip = model.Ip, LoginName = model.LoginName, Name = model.Name, Named = model.Named, LoginPassword = _customRepository.SetEncryption(model.LoginPassword) }; _serviceRepository.Add(newService); try { await _serviceRepository.SaveChangesAsync(); try { if (_monitorCore.IsSystemStandalone(model.DatabaseSystemId)) { var newInstance = new Instance { Active = model.Active, ServiceId = newService.Id, Hostname = model.Hostname, Ip = model.Ip, LoginName = model.LoginName, Name = model.Name, Named = model.Named, LoginPassword = _customRepository.SetEncryption(model.LoginPassword) }; _instanceRepository.Add(newInstance); await _instanceRepository.SaveChangesAsync(); _logger.InformationLog("Service and Instance: " + model.Name + " created successfully", "Create Service", string.Empty, userName); return(SystemSucceededTask.Success("Service and Instance: " + model.Name + " created successfully")); } } catch (Exception ex) { _logger.InformationLog(ex.Message, "Create Service and instance", ex.InnerException.Message, userName); return(SystemSucceededTask.Failed("Service and Instance: " + model.Name + " created unsuccessfully", ex.InnerException.Message, true, false)); } _logger.InformationLog("Service: " + model.Name + " created successfully", "Create Service", string.Empty, userName); return(SystemSucceededTask.Success("Service: " + model.Name + " created successfully")); } catch (Exception ex) { _logger.InformationLog(ex.Message, "Create Service", ex.InnerException.Message, userName); return(SystemSucceededTask.Failed("Service: " + model.Name + " created unsuccessfully", ex.InnerException.Message, true, false)); } }
public async Task CreateService(CreateServiceViewModel request, CancellationToken cancellationToken = default) { var entity = request.Cast(); await _context.Services.AddAsync(entity, cancellationToken); await _context.SaveChangesAsync(cancellationToken); }
public ActionResult CreateService(CreateServiceViewModel model) { if (ModelState.IsValid) { dataManager.PricesRepository.CreatePrice(0, model.ServiceName, model.ServiceCost, model.Type); return RedirectToAction("SelectTypeUslug","Services",new {s=model.Type}); } return View(model); }
public IHttpActionResult Post(CreateServiceViewModel model) { var service = new CreateServiceTransport { Description = model.Description }; ServiceManager.CreateService(service); return(Ok()); }
public IActionResult CreateService(long?id) { ViewBag.DataBaseList = _monitor.DatabaseSystemList(id ?? -1); ViewBag.SystemId = id; var service = new CreateServiceViewModel(); if (id != null) { service.DatabaseSystemId = id.Value; } service.Active = true; return(View(service)); }
public async Task <IActionResult> Create(CreateServiceViewModel model) { if (ModelState.IsValid) { var service = _mapper.Map <Service>(model); service.ImageURL = ImagesUpload(model); _repositoryManager.Service.CreateService(service); await _repositoryManager.saveAsync(); return(RedirectToAction(nameof(Success))); } return(View(model)); }
public IActionResult Create() { CreateServiceViewModel model = new CreateServiceViewModel(); var categoryList = _repositoryManager.Category.GetAllCategories.OrderBy(c => c.CategoryName).ToList(); categoryList.Insert(0, new Category { CategoryId = 0, CategoryName = "--- Select A Category ---" }); model.Categories = categoryList; return(View(model)); }
public void Post([FromBody] CreateServiceViewModel value) { Service service = new Service { Id = Guid.NewGuid(), Description = value.Description, Input = value.Input, Name = value.Name, OrganizationId = value.OrganizationId, Tags = value.Tags, Url = value.Url }; serviceManager.AddService(service); }
public ActionResult Create(CreateServiceViewModel model) { var service = new Service { Name = model.Name, Icon = model.Icon, Url = model.Url, Intro = model.Intro, Description = model.Description, CategoryId = model.CategoryId, CompanyId = model.CompanyId }; servicesService.InsertService(service); return(RedirectToAction("Index", "Service", new { area = "Admin" })); }
public async Task <IActionResult> CreateService(CreateServiceViewModel model) { var result = await _monitor.CreateService(model, GetCurrentUserAsync().Result.UserName); if (result.Succeeded) { _toastNotification.AddSuccessToastMessage(result.OkMessage, new ToastrOptions() { PositionClass = ToastPositions.TopCenter }); return(RedirectToAction("ListService", new { id = model.DatabaseSystemId })); } _toastNotification.AddErrorToastMessage(result.Errors, new ToastrOptions() { PositionClass = ToastPositions.TopCenter }); ViewBag.DataBaseList = _monitor.DatabaseSystemList(-1); return(View(model)); }
private string ImagesUpload(CreateServiceViewModel model) { string allFileName = string.Empty; if (model.Photos != null && model.Photos.Count > 0) { foreach (var photo in model.Photos) { string uploadFolder = Path.Combine(_webHostEnvironment.WebRootPath, "uploads"); string uniqueFileName = Guid.NewGuid().ToString() + "_" + photo.FileName; string filePath = Path.Combine(uploadFolder, uniqueFileName); photo.CopyToAsync(new FileStream(filePath, FileMode.Create)); if (string.IsNullOrEmpty(allFileName)) { allFileName += uniqueFileName; } allFileName = allFileName + "," + uniqueFileName; } } return(allFileName); }
public ActionResult Create() { var companies = companyService.GetAllCompanies().Select(x => new SelectListItem { Text = x.Name, Value = x.Id.ToString() }).ToList(); var categories = categoryService.GetAllCategories().Select(x => new SelectListItem { Text = x.Name, Value = x.Id.ToString() }).ToList(); var model = new CreateServiceViewModel { Companies = companies, Categories = categories }; return(View(model)); }
public IActionResult CreateService(CreateServiceViewModel model) { if (ModelState.IsValid) { if (model.Id == "0") { var service = new Service { Name = model.Name, Price = Convert.ToDecimal(model.Price), ImageUrl = model.ImageUrl, Description = model.Description, CategoryId = Convert.ToInt32(model.CategoryId), Duration = model.Duration }; _context.Add(service); } else { var service = new Service { Id = Convert.ToInt64(model.Id), Name = model.Name, Price = Convert.ToDecimal(model.Price), ImageUrl = model.ImageUrl, CategoryId = Convert.ToInt32(model.CategoryId), Description = model.Description, Duration = model.Duration }; _context.Update(service); } _context.SaveChanges(); return(RedirectToAction("Index", "Home")); } return(Ok()); }
public ActionResult CreateService(string s) { CreateServiceViewModel model = new CreateServiceViewModel(); model.Type = s; return View(model); }
public ServiceHandler(CreateServiceViewModel viewModel) { CreateServiceViewModel = viewModel; }
public async Task <ActionResult> CreateService(CreateServiceViewModel request) { await _serviceManagement.CreateService(request); return(Ok()); }