public async Task <ViewServiceModel> PostAsync(CreateServiceModel comment) { var commentForDb = new Comment { Text = comment.Text, ProductId = comment.ProductId, UserId = comment.UserId, WrittenOn = comment.WrittenOn, }; await this.commentRepository.AddAsync(commentForDb); await this.commentRepository.SaveChangesAsync(); var viewModel = new ViewServiceModel { Text = commentForDb.Text, Id = commentForDb.Id, UserId = commentForDb.UserId, WrittenOn = commentForDb.WrittenOn.ToString(GlobalConstants.DateTimeFormat), Username = this.userManager.FindByIdAsync(commentForDb.UserId).GetAwaiter().GetResult().UserName, }; return(viewModel); }
public async Task <ViewServiceModel> PostAsync(CreateServiceModel comment) { var commentForDb = new Comment { Text = comment.Text, AdvertisementId = comment.AdvertisementId, UserId = comment.UserId, WrittenOn = comment.WrittenOn }; await context.Comments.AddAsync(commentForDb); await context.SaveChangesAsync(); var viewModel = new ViewServiceModel { Text = commentForDb.Text, Id = commentForDb.Id, UserId = commentForDb.UserId, WrittenOn = commentForDb.WrittenOn.ToString(GlobalConstants.DateTimeFormat), Username = userManager.FindByIdAsync(commentForDb.UserId).GetAwaiter().GetResult().UserName }; return(viewModel); }
public ActionResult CreateService(int?groupId) { var model = new CreateServiceModel(); try { var group = db.CarServiceGroups.Where(r => r.groupId == (groupId ?? 0)).FirstOrDefault(); if (group != null) { model.groupId = group.groupId; model.groupName = group.groupName; } else { ModelState.AddModelError("", "Nhóm dịch vụ không hợp lệ!"); } } catch (Exception ex) { ModelState.AddModelError("", ex.ToString()); EventWriter.WriteEventLog("SystemController - CreateService: " + ex.ToString()); } return(View(model)); }
public IActionResult Create([FromBody] CreateServiceModel service) { var item = service.ToDomainModel(); _repository.Create(item); return(Ok(item.ServiceId)); }
public void HiddenLocation_When_Model_Is_Passed() { var model = new CreateServiceModel { Latitude = 13.37, Longitude = 60.61}; var htmlHelper = MvcMockHelpers.CreateHtmlHelper(new ViewDataDictionary(model)); const string expectedHtml = "<input id=\"Latitude\" name=\"Latitude\" type=\"hidden\" value=\"13.37\" /><input id=\"Longitude\" name=\"Longitude\" type=\"hidden\" value=\"60.61\" />"; var actualHtml = htmlHelper.HiddenLocation(); Assert.AreEqual(expectedHtml, actualHtml.ToHtmlString()); }
public void ImageUploadFor() { var model = new CreateServiceModel(); var viewData = new ViewDataDictionary <CreateServiceModel>(model); var htmlHelper = MvcMockHelpers.CreateHtmlHelper(viewData); const string expectedHtml = "<input accept=\"image/gif,image/jpeg,image/png\" id=\"Image\" name=\"Image\" type=\"file\" />"; var actualHtml = htmlHelper.ImageUploadFor(m => m.Image); Assert.AreEqual(expectedHtml, actualHtml.ToHtmlString()); }
public void HiddenLocation_When_Model_Is_Passed() { var model = new CreateServiceModel { Latitude = 13.37, Longitude = 60.61 }; var htmlHelper = MvcMockHelpers.CreateHtmlHelper(new ViewDataDictionary(model)); const string expectedHtml = "<input id=\"Latitude\" name=\"Latitude\" type=\"hidden\" value=\"13.37\" /><input id=\"Longitude\" name=\"Longitude\" type=\"hidden\" value=\"60.61\" />"; var actualHtml = htmlHelper.HiddenLocation(); Assert.AreEqual(expectedHtml, actualHtml.ToHtmlString()); }
public void ImageUploadFor() { var model = new CreateServiceModel(); var viewData = new ViewDataDictionary<CreateServiceModel>(model); var htmlHelper = MvcMockHelpers.CreateHtmlHelper(viewData); const string expectedHtml = "<input accept=\"image/gif,image/jpeg,image/png\" id=\"Image\" name=\"Image\" type=\"file\" />"; var actualHtml = htmlHelper.ImageUploadFor(m => m.Image); Assert.AreEqual(expectedHtml, actualHtml.ToHtmlString()); }
public async Task <IActionResult> Create(CreateServiceModel inputModel) { if (!this.ModelState.IsValid) { return(this.View(inputModel)); } var serviceServiceModel = AutoMapperConfig.MapperInstance.Map <CreateServiceInputModel>(inputModel); await this.servicesService.CreateAsync(serviceServiceModel); return(this.RedirectToAction("Index")); }
public void HiddenLocation_When_Model_Is_Passed_With_Model_State() { var model = new CreateServiceModel { Latitude = 13.37, Longitude = 60.61 }; var viewData = new ViewDataDictionary(model); viewData.ModelState.Add("Latitude", new ModelState { Value = new ValueProviderResult(13.37, "13.37", null) }); viewData.ModelState.Add("Longitude", new ModelState { Value = new ValueProviderResult(60.61, "60.61", null) }); var htmlHelper = MvcMockHelpers.CreateHtmlHelper(viewData); const string expectedHtml = "<input id=\"Latitude\" name=\"Latitude\" type=\"hidden\" value=\"13.37\" /><input id=\"Longitude\" name=\"Longitude\" type=\"hidden\" value=\"60.61\" />"; var actualHtml = htmlHelper.HiddenLocation(); Assert.AreEqual(expectedHtml, actualHtml.ToHtmlString()); }
public async Task <IActionResult> Post(CreateBindingModel input) { if (!this.ModelState.IsValid) { return(this.Redirect($"/Products/Details?productId={input.ProductId}")); } var serviceModel = new CreateServiceModel { Text = input.Text, ProductId = input.ProductId, WrittenOn = DateTime.UtcNow, UserId = this.userManager.GetUserAsync(this.HttpContext.User).GetAwaiter().GetResult().Id, }; var comment = await this.commentsService.PostAsync(serviceModel); return(this.Redirect($"/Products/Details?productId={input.ProductId}")); }
public void Create_Post_valid() { var sessionMock = new Mock <ISession>(); var nHbernateContextMock = new Mock <NHibernateContext>(sessionMock.Object, UserName); var createServiceModel = new CreateServiceModel(); var categories = GetSampleCategories(); nHbernateContextMock.Setup(c => c.ExecuteQuery(It.IsAny <Func <ISession, IList <Category> > >())) .Returns(categories); var fileSystemMock = new Mock <IFileSystem>(); var geoCodingServicemMock = new Mock <IGeoCodingService>(); var controller = new ServicesController(nHbernateContextMock.Object, fileSystemMock.Object, geoCodingServicemMock.Object); controller.SetFakeControllerContext(MvcMockHelpers.FakeAuthenticatedHttpContext("~/Services/Create/", UserName)); controller.SetUserInfo(); controller.Create(createServiceModel); nHbernateContextMock.Verify(c => c.ExecuteCommand(It.IsAny <ICommand>())); }
public ActionResult Create(CreateServiceModel createServiceModel) { if (ModelState.IsValid) { FileBase image = createServiceModel.Image != null ? new FileBaseAdapter(createServiceModel.Image) : null; var isServiceOffering = createServiceModel.Type == 1; var command = new CreateServiceCommand(isServiceOffering, createServiceModel.Title, createServiceModel.Body, createServiceModel.CategoryId, UserInfo.Id, createServiceModel.Latitude, createServiceModel.Longitude, null, _fileSystem, image); ExecuteCommand(command); TempData[ViewDataKeys.Message] = new SuccessMessage(string.Format(Resources.EntityCreateSuccess, "Service")); return(RedirectToAction("Profile", "Accounts")); } ViewData[ViewDataKeys.Categories] = GetCategories(); ViewData[ViewDataKeys.ServiceTypes] = GetServiceTypes(); return(View()); }
public ActionResult CreateService(CreateServiceModel model) { if (ModelState.IsValid) { try { var service = db.CarServices .Where(r => r.groupId == model.groupId && String.Compare(r.serviceName, model.serviceName, true) == 0) .FirstOrDefault(); if (service == null) { service = new CarService(); service.serviceName = model.serviceName; service.groupId = model.groupId; service.iconURL = model.iconURL; service.description = model.description; service.owner = User.Identity.Name; service.creationDate = DateTime.Now; service.sortIdx = db.CarServices.Count() + 1; db.CarServices.Add(service); db.SaveChanges(); return(RedirectToAction("ListServices", new { groupID = model.groupId })); } else { ModelState.AddModelError("", "Dịch vụ tên <strong>" + model.serviceName + "</strong> đã tồn tại trong hệ thống. Vui lòng nhập tên khác!"); } } catch (Exception ex) { ModelState.AddModelError("", ex.ToString()); EventWriter.WriteEventLog("SystemController - CreateService: " + ex.ToString()); } } return(View(model)); }
public async Task<IActionResult> Post(CreateBindingModel input) { if (!ModelState.IsValid) { return Redirect($"/Advertisement/Details?id={input.AdvertisementId}"); } var serviceModel = new CreateServiceModel { Text = input.Text, AdvertisementId = input.AdvertisementId, WrittenOn = DateTime.UtcNow, UserId = userManager.GetUserAsync(HttpContext.User).GetAwaiter().GetResult().Id }; var comment = await commentService.PostAsync(serviceModel); var ad = await advertisementService.GetByIdAsync(input.AdvertisementId); await NotifyAsync(comment, ad); return Redirect($"/Advertisement/Details?id={input.AdvertisementId}"); }
public ResponseWrapper <CreateServiceModel> CreateService(CreateServiceInputModel model) { var newEntity = new Service { Name = model.Name, PluralName = model.PluralName, ApplicationId = model.ApplicationId, }; context .Services .Add(newEntity); context.SaveChanges(); var response = new CreateServiceModel { ServiceId = newEntity.ServiceId, Name = newEntity.Name, PluralName = newEntity.PluralName, ApplicationId = newEntity.ApplicationId, }; return(new ResponseWrapper <CreateServiceModel>(_validationDictionary, response)); }
public ActionResult Create(CreateServiceModel createServiceModel) { if (ModelState.IsValid) { FileBase image = createServiceModel.Image != null ? new FileBaseAdapter(createServiceModel.Image) : null; var isServiceOffering = createServiceModel.Type == 1; var command = new CreateServiceCommand(isServiceOffering, createServiceModel.Title, createServiceModel.Body, createServiceModel.CategoryId, UserInfo.Id, createServiceModel.Latitude, createServiceModel.Longitude, null, _fileSystem, image); ExecuteCommand(command); TempData[ViewDataKeys.Message] = new SuccessMessage(string.Format(Resources.EntityCreateSuccess, "Service")); return RedirectToAction("Profile", "Accounts"); } ViewData[ViewDataKeys.Categories] = GetCategories(); ViewData[ViewDataKeys.ServiceTypes] = GetServiceTypes(); return View(); }
public void Create_Post_valid() { var sessionMock = new Mock<ISession>(); var nHbernateContextMock = new Mock<NHibernateContext>(sessionMock.Object, UserName); var createServiceModel = new CreateServiceModel(); var categories = GetSampleCategories(); nHbernateContextMock.Setup(c => c.ExecuteQuery(It.IsAny<Func<ISession, IList<Category>>>())) .Returns(categories); var fileSystemMock = new Mock<IFileSystem>(); var geoCodingServicemMock = new Mock<IGeoCodingService>(); var controller = new ServicesController(nHbernateContextMock.Object, fileSystemMock.Object, geoCodingServicemMock.Object); controller.SetFakeControllerContext(MvcMockHelpers.FakeAuthenticatedHttpContext("~/Services/Create/", UserName)); controller.SetUserInfo(); controller.Create(createServiceModel); nHbernateContextMock.Verify(c => c.ExecuteCommand(It.IsAny<ICommand>())); }
public IActionResult Update([FromBody] CreateServiceModel service) { //TODO: Add Implementation -> return updated service ID return(Ok()); }