private async Task <ServicesViewModel> GetServiceModelWithRatings(Service service, int userId) { var categories = await _servicesService.GetCategoryToService(service.Id); var ratingAvg = await _ratingService.AvgRating(service.Id); var userRating = await _ratingService.GetRatingByuserId(service.Id, userId); var categoriesView = new List <CategoryViewModel>(); foreach (var item in categories) { categoriesView.Add(new CategoryViewModel { Id = item.Id, Name = item.Name }); } var model = new ServiceCategoryViewModel { Id = service.Id, Name = service.Name, Description = service.Description, Categories = categoriesView, Cost = service.Cost, Floor = service.Floor, Hall = service.Hall, AgeFrom = service.AgeFrom, Rating = ratingAvg != null ? (decimal)ratingAvg : 0, userRating = userRating }; return(model); }
public ActionResult AddNew(ServiceCategoryViewModel serviceCategoryViewModel) { try { if (ModelState.IsValid) { ServiceCategoryRepository ServiceCategoryRepository = new ServiceCategoryRepository(new AutoSolutionContext()); bool IsExist = ServiceCategoryRepository.isExist(serviceCategoryViewModel.ServiceCategoryName); if (!IsExist) { ServiceCategory serviceCategory = new ServiceCategory(); serviceCategory.ServiceCategoryName = serviceCategoryViewModel.ServiceCategoryName; serviceCategory.ServiceCategoryCode = serviceCategoryViewModel.ServiceCategoryCode; serviceCategory.Description = serviceCategoryViewModel.Description; _unitOfWork.ServiceCategory.Add(serviceCategory); _unitOfWork.Complete(); _unitOfWork.Dispose(); return(RedirectToAction("GetServiceCategory")); } else { return(RedirectToAction("GetServiceCategory")); } } } catch (Exception) { throw; } return(View()); }
public ActionResult Edit(string id) { try { if (string.IsNullOrEmpty(id)) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var item = _unitOfWork.ServiceCategory.GetByID(Convert.ToInt32(id)); ServiceCategoryViewModel serviceCategoryViewModel = new ServiceCategoryViewModel(); serviceCategoryViewModel.ServiceCategoryId = item.ServiceCategoryId; serviceCategoryViewModel.ServiceCategoryName = item.ServiceCategoryName; serviceCategoryViewModel.ServiceCategoryCode = item.ServiceCategoryCode; serviceCategoryViewModel.Description = item.Description; if (serviceCategoryViewModel != null) { return(PartialView("_EditServiceCategory", serviceCategoryViewModel)); } else { return(HttpNotFound()); } } catch (Exception) { throw; } }
public async Task <ServiceCategoryViewModel> AddServiceCategory(ServiceCategoryViewModel serviceCategory) { var domainServiceCategory = new ServiceCategory( serviceCategory.SiteId, serviceCategory.Name, serviceCategory.Description, serviceCategory.AllowOnlineScheduling, serviceCategory.ScheduleTypeId ); _serviceCategoryRepository.Add(domainServiceCategory); //_session.Add<ServiceCategory>(domainServiceCategory); //_session.Commit(); var serviceCategoryCreatedEvent = new ServiceCategoryCreatedEvent( domainServiceCategory.SiteId, domainServiceCategory.Id, domainServiceCategory.Name, domainServiceCategory.Description, domainServiceCategory.AllowOnlineScheduling, domainServiceCategory.ScheduleTypeId ); await _businessIntegrationEventService.PublishThroughEventBusAsync(serviceCategoryCreatedEvent); serviceCategory.Id = domainServiceCategory.Id; return(serviceCategory); }
public ActionResult Edit(ServiceCategoryViewModel viewModel) { try { if (ModelState.IsValid) { var entity = Mapper.Map <ServiceCategoryViewModel, ServiceCategory>(viewModel); _categoryService.Update(entity); viewModel.Locales.ToList().ForEach(l => { _localizedEntityService.SaveLocalizedValue(entity, e => e.Name, l.Name, l.LanguageId); _localizedEntityService.SaveLocalizedValue(entity, e => e.Content, l.Content, l.LanguageId); }); } } catch (Exception e) { ModelState.AddModelError("", e.Message); return(View(viewModel)); } return(RedirectToAction("Index")); }
// GET: Admin/ServiceCategory/Create public ActionResult Create() { var viewModel = new ServiceCategoryViewModel(); AddLocales(viewModel.Locales, (locale, languageId) => { }); return(View(viewModel)); }
public async Task <ServiceCategoryViewModel> Create(ServiceCategoryViewModel serviceCategory) { ServiceCategory obj = ViewModelToEntityMapper.Map(serviceCategory); var serviceCategoryInfo = this.ServiceCategoryRepository.Add(obj); return(EntityToViewModelMapper.Map(serviceCategoryInfo)); }
public ServiceCategoryViewModel GetServiceCategory(int PageNo, int TotalCount, string SearchTerm) { var ServiceCategoryViewModel = new ServiceCategoryViewModel() { ServiceCategoriesList = AutoSolutionContext.ServiceCategories.OrderBy(x => x.ServiceCategoryName).Where(x => x.ServiceCategoryName.Contains(SearchTerm)).Skip((PageNo - 1) * 10).Take(10).ToList(), Pager = new Pager(TotalCount, PageNo, 10) }; return(ServiceCategoryViewModel); }
public async Task <IActionResult> AddServiceCategory([FromBody] ServiceCategoryViewModel request ) { if (!ModelState.IsValid) { return((IActionResult)BadRequest()); } var result = await _serviceCategoryService.AddServiceCategory(request); return(CreatedAtAction(nameof(AddServiceCategory), new { id = result.Id }, null)); }
public async Task <object> ServiceView(int id, int userId) { var service = await _servicesService.GetService(id); var categories = await _servicesService.GetCategoryToService(id); if (service == null) { return(JsonResults.Error(errorNum: 404, errorMessage: "Service not found")); } var ratingAvg = await _ratingService.AvgRating(service.Id); var userRating = await _ratingService.GetRatingByuserId(service.Id, userId); if (ratingAvg == null) { ratingAvg = 0; } if (userRating == null) { userRating = 0; } var categoriesView = new List <CategoryViewModel>(); foreach (var item in categories) { categoriesView.Add(new CategoryViewModel { Id = item.Id, Name = item.Name }); } var model = new ServiceCategoryViewModel { Id = service.Id, Name = service.Name, Description = service.Description, Categories = categoriesView, Cost = service.Cost, Floor = service.Floor, Hall = service.Hall, AgeFrom = service.AgeFrom, Rating = ratingAvg != null ? (decimal)ratingAvg : 0, userRating = userRating }; return(JsonResults.Success(model)); }
public static ServiceCategory Map(ServiceCategoryViewModel viewModel, ServiceCategory entity) { if (viewModel == null || entity == null) { return(null); } entity.ServiceCategoryId = viewModel.ServiceCategoryId; entity.ServiceCategoryName = viewModel.ServiceCategoryName; entity.SortOrder = viewModel.SortOrder; entity.IsActive = viewModel.IsActive; return(entity); }
public async Task <ServiceCategoryViewModel> Update(ServiceCategoryViewModel serviceCategory) { var serviceCategoryInfo = this.ServiceCategoryRepository.Find(serviceCategory.ServiceCategoryId); if (serviceCategoryInfo != null) { serviceCategoryInfo = ViewModelToEntityMapper.Map(serviceCategory, serviceCategoryInfo); serviceCategoryInfo = this.ServiceCategoryRepository.Update(serviceCategoryInfo); return(EntityToViewModelMapper.Map(serviceCategoryInfo)); } return(serviceCategory); }
public static ServiceCategory Map(ServiceCategoryViewModel viewModel) { if (viewModel == null) { return(null); } return(new ServiceCategory { ServiceCategoryId = viewModel.ServiceCategoryId, ServiceCategoryName = viewModel.ServiceCategoryName, SortOrder = viewModel.SortOrder, IsActive = viewModel.IsActive }); }
public async Task <IActionResult> CreateUpdateCategory(int?id) { var model = new ServiceCategoryViewModel(); if (id != null) { model = await _servicesService.GetServiceCategoryForCRUD(id.Value); if (!string.IsNullOrEmpty(model.Photo)) { ViewBag.AvatarPreview = "<img src=" + model.Photo + " alt=\"Avatar\">"; } } ViewBag.ShiftCenterTypes = MyEnumExtensions.EnumToSelectList <ShiftCenterType>().ToList(); return(PartialView(model)); }
public ActionResult _SearchPartial(ServiceCategoryViewModel model) { var list = (from sc in _context.Master_ChicCut_ServiceCategoryModel join spc in _context.Master_ChicCut_ServiceParentCategoryModel on sc.ServiceParentCategoryId equals spc.ServiceParentCategoryId into Service from sv in Service.DefaultIfEmpty() orderby sc.ServiceCategoryId select new ServiceCategoryViewModel() { ServiceCategoryId = sc.ServiceCategoryId, ServiceName = sc.ServiceName, ServiceParentCategoryName = sv.ServiceParentCategoryName, OrderBy = sc.OrderBy, Actived = sc.Actived, Type = sc.Type }) .ToList(); return(PartialView(list)); }
public ActionResult Delete(ServiceCategoryViewModel viewModel) { try { if (ModelState.IsValid) { var entity = Mapper.Map <ServiceCategoryViewModel, ServiceCategory>(viewModel); _categoryService.Delete(entity); return(RedirectToAction("Index")); } } catch (Exception e) { ModelState.AddModelError("", e.Message); } return(View(viewModel)); }
public ActionResult Edit(ServiceCategoryViewModel serviceCategoryViewModel) { try { if (serviceCategoryViewModel == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ServiceCategory serviceCategory = new ServiceCategory(); serviceCategory.ServiceCategoryId = serviceCategoryViewModel.ServiceCategoryId; serviceCategory.ServiceCategoryName = serviceCategoryViewModel.ServiceCategoryName; serviceCategory.ServiceCategoryCode = serviceCategoryViewModel.ServiceCategoryCode; serviceCategory.Description = serviceCategoryViewModel.Description; _unitOfWork.ServiceCategory.Update(serviceCategory); _unitOfWork.Complete(); _unitOfWork.Dispose(); } catch (Exception) { throw; } return(RedirectToAction("GetServiceCategory")); }
public async Task <IActionResult> CreateUpdateCategory(ServiceCategoryViewModel model) { var message = model.Id != null ? Messages.ItemUpdatedSuccessFully : Messages.ItemAddedSuccessFully; var strategy = _dbContext.Database.CreateExecutionStrategy(); await strategy.ExecuteAsync(async() => { using (var transaction = _dbContext.Database.BeginTransaction()) { if (model.Id != null) { var group = await _dbContext.ServiceCategories.FindAsync(model.Id); if (group == null) { throw new AwroNoreException("Service Category Not Found"); } group.Name = model.Name; group.Name_Ar = model.Name_Ar; group.Name_Ku = model.Name_Ku; group.CenterType = model.CenterType; group.UpdatedAt = DateTime.Now; _dbContext.ServiceCategories.Attach(group); _dbContext.Entry(group).State = EntityState.Modified; await _dbContext.SaveChangesAsync(); if (model.ImageUpload != null) { var(newName, thumbName, dirPath, baseUrl) = _uploadService.GenerateServiceCategoryLogoName(group.Id, model.ImageUpload); group.Photo = $"{baseUrl}/{thumbName}"; _dbContext.ServiceCategories.Attach(group); _dbContext.Entry(group).State = EntityState.Modified; await _dbContext.SaveChangesAsync(); await _uploadService.UploadServiceCategoryLogoAsync(model.ImageUpload, dirPath, newName, thumbName); } } else { var group = new ServiceCategory { Name = model.Name, Name_Ku = model.Name_Ku, Name_Ar = model.Name_Ar, CenterType = model.CenterType, CreatedAt = DateTime.Now, }; await _dbContext.ServiceCategories.AddAsync(group); await _dbContext.SaveChangesAsync(); var(newName, thumbName, dirPath, baseUrl) = _uploadService.GenerateServiceCategoryLogoName(group.Id, model.ImageUpload); group.Photo = $"{baseUrl}/{thumbName}"; _dbContext.ServiceCategories.Attach(group); _dbContext.Entry(group).State = EntityState.Modified; await _dbContext.SaveChangesAsync(); await _uploadService.UploadServiceCategoryLogoAsync(model.ImageUpload, dirPath, newName, thumbName); } transaction.Commit(); } }); return(Json(new { success = true, message })); }