public async Task <IActionResult> Create(CreateVM createVm) { var result = await _cloudFlare.CreatePageRule(createVm.Domain, createVm.MatchUrlBlob, createVm.ForwardingUrl); if (result) { TempData["Message"] = "Successfully created rule matching: " + createVm.MatchUrlBlob; return(RedirectToAction(nameof(GetRules), new { domain = createVm.Domain })); } throw new System.Exception("Failed to create"); }
public ActionResult Create() { CreateVM model = new CreateVM() { Groups = db.Groups.ToList(), Student = null, Action = "Create" }; return(View(model)); }
public PartialViewResult Create(long id = 0) { var model = new CreateVM(); if (id > 0) { model.ParentId = id; } ViewBag.ListDepartment = _departmentService.GetDropdown("Name", "Id", (long)id); return(PartialView("_CreatePartial", model)); }
public ActionResult Viewfood(int id) { var fd = db.Foods.Include(f => f.Restaurant).Where(f => f.RstID == id).ToList(); var view = new CreateVM() { _food = fd }; TempData["message"] = "Food Added to Plate Successfully"; return(View(fd)); }
/// <summary> /// Tạo mới trạng thái trong luồng xử lý /// </summary> /// <param name="id">id luồng xử lý</param> /// <returns></returns> public PartialViewResult Create(int id) { var WF_STREAMBusiness = Get <WF_STREAMBusiness>(); var DM_VAITROBusiness = Get <DM_VAITROBusiness>(); var DM_DANHMUC_DATABusiness = Get <DM_DANHMUC_DATABusiness>(); var model = new CreateVM(); model.DsVaiTro = DM_VAITROBusiness.DsVaiTro(null); model.DsChucVu = DM_DANHMUC_DATABusiness.DsByMaNhomNull(DMLOAI_CONSTANT.CHUCVU); model.LuongXuLy = WF_STREAMBusiness.Find(id); return(PartialView("_CreatePartial", model)); }
public void Create(CreateVM model) { var course = new Course() { Description = model.Description, Name = model.Name, StartDate = model.StartDate, EndDate = model.EndDate }; Contex.Courses.Add(course); Contex.SaveChanges(); }
public IActionResult Create() { CreateVM model = new CreateVM(); ProductsRepository productsRepo = new ProductsRepository(); model.Products = productsRepo.GetAll(); model.Quantities = new int[model.Products.Count]; model.Ids = new int[model.Products.Count]; for (int i = 0; i < model.Ids.Length; i++) { model.Ids[i] = model.Products[i].Id; } return(View(model)); }
public IActionResult Create(CreateVM task) // Model binding { // Validate (server-side) if (!ModelState.IsValid) { return(View(task)); } // Add customer to DB service.Create(task); // Redirect to index return(RedirectToAction("Create")); }
/// <summary> /// id danh mục /// </summary> /// <param name="id"></param> /// <returns></returns> public PartialViewResult Create(int id) { DM_NHOMDANHMUCBusiness = Get <DM_NHOMDANHMUCBusiness>(); var CCBusiness = Get <CCTC_THANHPHANBusiness>(); var model = new CreateVM(); model.DanhMuc = DM_NHOMDANHMUCBusiness.Find(id); model.LstDept = CCBusiness.repository.All().Where(x => x.TYPE == 10).Select(x => new SelectListItem() { Value = x.ID.ToString(), Text = x.NAME, }).ToList(); return(PartialView("_CreatePartial", model)); }
public ActionResult Create(CreateVM ViewModel) { if (ModelState.IsValid) { var poll = new Poll(); poll.Create(ViewModel); poll.Creator = User.Identity.GetUserName(); db.Polls.Add(poll); db.SaveChanges(); return(RedirectToAction("Details", new { id = poll.Id })); } return(View(ViewModel)); }
public ActionResult Create([Bind(Include = "userID,firstName,lastName,age")] User user) { if (ModelState.IsValid) { db.userDB.Add(user); db.SaveChanges(); return(RedirectToAction("Index")); } CreateVM vm = new CreateVM(); vm.user = new UserVM(user); vm.username = User.Identity.Name; return(View(vm)); }
public ActionResult Create(CreateVM ct) { using (UserDBEntities1 db = new UserDBEntities1()) { if (db.CollectionTables.Any(x => x.Title == ct.collectionTable.Title)) { ViewBag.DuplicateMessage = "Item already exists."; return(View("Create", ct)); } db.CollectionTables.Add(ct.collectionTable); db.SaveChanges(); } ModelState.Clear(); ViewBag.SuccessMessage = "Creation Successful."; return(View("Create", new CreateVM())); }
// GET: WorkLog/Create public ActionResult Create(int id) { if (HttpContext.Session.GetObjectFromJson <LoggedUser>("loggedUser") == null) { return(RedirectToAction("Login", "Home")); } using ToDoManagerContext context = new ToDoManagerContext(); CreateVM model = new CreateVM { TaskId = id, UserId = HttpContext.Session.GetObjectFromJson <LoggedUser>("loggedUser").Id }; return(View(model)); }
public IActionResult Create(CreateVM createVM) { User u = repo.GetUser(User.Identity.Name); if (u.IsBanned) { if (u.IsBanned) { return(RedirectToAction("Banned", "Error")); } } int Id = repo.CreateAd(createVM, u.Id); return(RedirectToAction("Ad", "Home", new { id = Id, category = createVM.Category })); }
public void UpdateCarViewRedirectToGetCars() { var model = new CreateVM() { Car = new CarDM() { DateOfCreate = DateTime.Now } }; _mockRentMapper.Setup(x => x.ToCarDTO.Map <CarDM, CarDTO>(model.Car)).Returns(new CarDTO()); RedirectToRouteResult result = _controller.UpdateCar(model) as RedirectToRouteResult; Assert.AreEqual("GetCars", result.RouteValues["action"]); }
/// <summary> /// Create car data transfer object. /// </summary> /// <param name="model">Car model</param> /// <returns>New car</returns> private CarDTO _createCarDTO(CreateVM model) { CarDTO carDTO = _rentMapperDM.ToCarDTO.Map <CarDM, CarDTO>(model.Car); List <PropertyDTO> properties = new List <PropertyDTO>(); if (model.PropertyNames != null && model.PropertyNames.Length > 0) { for (int i = 0; i < model.PropertyNames.Count(); i++) { properties.Add(new PropertyDTO() { Name = model.PropertyNames[i], Text = model.PropertyValues[i] }); } } carDTO.Properties = properties; List <ImageDM> images = new List <ImageDM>(); int ofset = 0; if (model.Photos != null && model.Photos.Length > 0) { ofset = model.Photos.Length; for (int i = 0; i < model.Photos.Length; i++) { images.Add(new ImageDM { Text = model.Alts[i], Photo = _rentService.GetCar(model.Car.Id).Images.First(x => x.Id.ToString() == model.Photos[i]).Photo }); } } if (model.Images != null) { for (int i = 0; i < model.Images.Length; i++) { using (var reader = new BinaryReader(model.Images[i].InputStream)) images.Add(new ImageDM { Photo = reader.ReadBytes(model.Images[i].ContentLength), Text = model.Alts[i + ofset] }); } } carDTO.Images = _rentMapperDM.ToImageDTO.Map <List <ImageDM>, IEnumerable <ImageDTO> >(images); return(carDTO); }
public async Task <IActionResult> Create(CreateVM model) { if (!ModelState.IsValid) { return(View(model)); } ProductType type = new ProductType() { Name = model.Name }; _dbContext.ProductTypes.Add(type); await _dbContext.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
public ActionResult Create(CreateVM vm) { if (ModelState.IsValid) { User user = new Models.User(); user.age = vm.age; user.firstName = vm.lastName; user.lastName = vm.lastName; db.userDB.Add(user); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(vm)); }
public ActionResult Create(CreateVM model) { //if (HttpContext.Session.GetObjectFromJson<LoggedUser>("loggedUser") == null) // return RedirectToAction("Login", "Home"); //if (!HttpContext.Session.GetObjectFromJson<LoggedUser>("loggedUser").IsAdmin) // return RedirectToAction("Login", "Home"); if (!ModelState.IsValid) { return(View(model)); } if (model.Password == model.ConfirmPassword) { using RestaurantManagerContext context = new RestaurantManagerContext(); if (context.Users.Count() == 0) { User item = new User { Username = model.Username, Password = model.ConfirmPassword, Email = model.Email, IsAdmin = true }; context.Users.Add(item); context.SaveChanges(); } else { User item = new User { Username = model.Username, Password = model.ConfirmPassword, Email = model.Email, IsAdmin = false }; context.Users.Add(item); context.SaveChanges(); } } return(RedirectToAction("Index", "User")); }
// GET: Task/Create public ActionResult Create(int id) { if (HttpContext.Session.GetObjectFromJson <LoggedUser>("loggedUser") == null) { return(RedirectToAction("Login", "Home")); } using ToDoManagerContext context = new ToDoManagerContext(); CreateVM model = new CreateVM { ProjectId = id, UserPairs = context.Users.Select(u => new SelectListItem { Value = u.Id.ToString(), Text = u.Username }).ToList() }; return(View(model)); }
public ActionResult CreateCar(CreateVM model) { if (model.Car.DateOfCreate.Date > DateTime.Now.Date || model.Car.DateOfCreate.Date < DateTime.Now.AddYears(-30).Date) { ModelState.AddModelError("DateOfCreate", "Неверная дата"); } if (ModelState.IsValid) { CarDTO carDTO = _createCarDTO(model); _adminService.CreateCar(carDTO); _logWriter.CreateLog("Добавил автомобиль ", User.Identity.GetUserId()); return(RedirectToAction("GetCars")); } return(View(model)); }
public async Task <IActionResult> Update(CreateVM vm) { User u = repo.GetUser(User.Identity.Name); Ad ad = repo.GetAd(vm.Category, vm.Id); if (ad == null) { return(RedirectToAction("PageNotFound", "Error")); } if (ad.UserId != u.Id) { return(RedirectToAction("Forbidden", "Error")); } repo.UpdateAd(vm, (userId, message) => Notify(userId, "Price of observed item changed", message)); await Notify(ad.UserId, "Price of observed item changed", "testing..."); return(RedirectToAction("Ad", "Home", new { id = vm.Id, category = vm.Category })); }
public IActionResult Create([FromBody] CreateVM model) { if (ModelState.IsValid) { try { var client = facade.CreateClient(model.firstname, model.lastname, model.businessName, model.invoicePrefix, model.address, model.email, model.primaryPhone); return(Ok(client)); } catch (BusinessRuleException ex) { return(BadRequest(ex.Message)); } } else { return(BadRequest(ModelState.Keys)); } }
public async Task <IActionResult> Create(CreateVM model) { if (!ModelState.IsValid) { return(View(model)); } DeliveryMethod deliveryMethod = new DeliveryMethod() { Name = model.Name, Description = model.Description, Price = model.Price }; _dbContext.DeliveryMethods.Add(deliveryMethod); await _dbContext.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
public IActionResult Create(CreateVM model) { UnitOfWork uow = new UnitOfWork(); OrdersRepository ordersRepo = new OrdersRepository(uow); OrderProductsRepository opRepo = new OrderProductsRepository(uow); UsersRepository usersRepo = new UsersRepository(uow); ProductsRepository productsRepo = new ProductsRepository(uow); User loggedUsed = usersRepo.GetFirstOrDefault(u => u.Username == HttpContext.Session.GetString("LoggedUsername")); uow.BeginTransaction(); Order order = new Order(DateTime.Now, loggedUsed.Id); try { ordersRepo.Insert(order); for (int i = 0; i < model.Ids.Length; i++) { if (model.Quantities[i] > 0) { OrderProduct op = new OrderProduct(); Product p = productsRepo.GetFirstOrDefault(pr => pr.Id == model.Ids[i]); op.Order = order; op.ProductId = p.Id; op.PriceSold = p.CurrentPrice; op.Quantity = model.Quantities[i]; opRepo.Insert(op); } } uow.Commit(); } catch (Exception) { uow.Rollback(); } finally { uow.Dispose(); } return(RedirectToAction("My", "Orders")); }
public static TEntity Create <TEntity>(this CreateVM vm, Guid?id = null) where TEntity : Entity, new() { var tmp = new TEntity { Id = id ?? GuidUtil.NewSequentialId(), CreatedOn = DateTimeUtil.GetCurrentTime() }; if (vm == null) { return(tmp); } var sourceProps = vm.GetType().GetProperties(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance) .ToDictionary(a => a.Name, a => a); var targetProps = typeof(TEntity).GetProperties(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance) .ToDictionary(a => a.Name, a => a); var sourceNames = sourceProps.Keys; var targetNames = targetProps.Keys; var mixedNames = targetNames.Intersect(sourceNames); foreach (var name in mixedNames) { var sourceProp = sourceProps[name]; try { var sourceVal = sourceProp.GetValue(vm); if (sourceVal != null) { var targetProp = targetProps[name]; targetProp.SetValue(tmp, sourceVal); } } catch { } } return(tmp); }
public ActionResult Create(CreateVM vm) { if (!ModelState.IsValid) { return(View(vm)); } if (Session["LoggedUser"] == null) { return(View(vm)); } TodoItemBL todoItemBL = new TodoItemBL(); UserBL userBL = new UserBL(); int userID = userBL.GetLoggedUserID((string)Session["LoggedUser"]); TodoItem todoItem = new TodoItem(vm, userID); todoItemBL.AddItem(todoItem); return(RedirectToAction("List", "List")); }
public JsonResult Create(CreateVM model) { var result = new JsonResultBO(true); try { if (ModelState.IsValid) { var savedModel = _IMapper.Map <TD_CauHinhSangLocUngVien>(model); _TD_CauHinhSangLocUngVienService.Create(savedModel); } } catch (Exception ex) { result.Status = false; result.Message = ex.Message; _ILog.Error("Lỗi ở thêm mới cấu hình sàng lọc ứng viên", ex); } return(Json(result)); }
public async Task <IActionResult> Create(CreateVM model) { if (!ModelState.IsValid) { return(View(model)); } Sale sale = new Sale() { Name = model.Name, DiscountRate = model.DiscountRate, DateStart = model.DateStart, DateEnd = model.DateEnd }; _dbContext.Sales.Add(sale); await _dbContext.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
public ActionResult details(int id) { try { string _connectionString = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString as string; using (IDbConnection db = new SqlConnection(_connectionString)) { CreateVM pageVM = new CreateVM(); var query = "GetPhotoById"; var param = new DynamicParameters(); param.Add("Id", id); pageVM.Uploader = db.Query <PhotoUpload>(query, param, commandType: CommandType.StoredProcedure).First(); return(View(pageVM)); } } catch (Exception ex) { return(Content(ex.Message)); } }