public async Task <IActionResult> Create([Bind("Name,CategoryId")] Subcategory subcategory) { try { if (ModelState.IsValid) { var subcategories = _context.Subcategories.Where(s => s.Name == subcategory.Name).FirstOrDefault(); if (subcategories != null) { ModelState.AddModelError(string.Empty, "This subcategory already exists"); return(RedirectToAction("Create", "Subcategories", new { categoryId = subcategory.CategoryId })); } else { _context.Add(subcategory); await _context.SaveChangesAsync(); //return RedirectToAction(nameof(Index)); return(RedirectToAction("Index", "Subcategories", new { Id = subcategory.CategoryId, name = _context.Categories.Where(c => c.Id == subcategory.CategoryId).FirstOrDefault().Name })); } } } catch (DbUpdateException /* ex */) { //Log the error (uncomment ex variable name and write a log. ModelState.AddModelError("", "Unable to save changes. " + "Try again, and if the problem persists " + "see your system administrator."); } //PopulateDepartmentsDropDownList(subcategory.CategoryId); return(View(subcategory)); //return RedirectToAction("Index", "Subcategories", new { id = subcategory.CategoryId, name = _context.Categories.Where(c => c.Id == subcategory.CategoryId).FirstOrDefault().Name }); }
public IActionResult AddCategory(string Name) { User CurrUser = GetCurrentUserAsync().Result; Category NewCategory = new Category { Name = Name, UserId = CurrUser.Id, }; _context.Add(NewCategory); _context.SaveChanges(); return(RedirectToAction("Index")); }
public async Task <bool> CreateBuildingActivity(BuildingActivity buildingActivity) { _context.Add(buildingActivity); var res = await _context.SaveChangesAsync(); return(res > 0); }
public async Task <IActionResult> Create([Bind("Info,Date,ProductId,UserId,UserName")] Comment comment, int num, string searchString) { try { if (ModelState.IsValid) { _context.Add(comment); //User user = await _userMenager.FindByIdAsync(comment.UserId); await _context.SaveChangesAsync(); return(RedirectToAction("Index", "Comments", new { Id = comment.ProductId, name = _context.Products.Where(c => c.Id == comment.ProductId).FirstOrDefault().Name, num = num, searchString = searchString })); } else { return(RedirectToAction("Create", "Comments", new { productId = comment.ProductId, userId = comment.UserId, num = num, searchString = searchString })); } } catch (DbUpdateException /* ex */) { //Log the error (uncomment ex variable name and write a log. ModelState.AddModelError("", "Unable to save changes. " + "Try again, and if the problem persists " + "see your system administrator."); } //PopulateDepartmentsDropDownList(subcategory.CategoryId); //return View(subcategory); return(RedirectToAction("Index", "Comments", new { Id = comment.ProductId, name = _context.Products.Where(c => c.Id == comment.ProductId).FirstOrDefault().Name, num = num, searchString = searchString })); }
public async Task <IActionResult> Create([Bind("Name")] Category category) { try { if (ModelState.IsValid) { var categories = _context.Categories.Where(c => c.Name == category.Name).FirstOrDefault(); if (categories != null) { ModelState.AddModelError(string.Empty, "This category already exists"); } else { _context.Add(category); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } } } catch (DbUpdateException /* ex */) { //Log the error (uncomment ex variable name and write a log. ModelState.AddModelError("", "Unable to save changes. " + "Try again, and if the problem persists " + "see your system administrator."); } return(View(category)); }
public async Task <IActionResult> Create([Bind("Id,Name")] Ingredient ingredient) { if (ModelState.IsValid) { _context.Add(ingredient); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(ingredient)); }
public async Task <IActionResult> Create([Bind("Id,AbsoluteRefreshTokenLifetime,AccessTokenLifetime,AccessTokenType,AllowAccessTokensViaBrowser,AllowOfflineAccess,AllowPlainTextPkce,AllowRememberConsent,AlwaysIncludeUserClaimsInIdToken,AlwaysSendClientClaims,AuthorizationCodeLifetime,ClientId,ClientName,ClientUri,EnableLocalLogin,Enabled,IdentityTokenLifetime,IncludeJwtId,LogoUri,LogoutSessionRequired,LogoutUri,PrefixClientClaims,ProtocolType,RefreshTokenExpiration,RefreshTokenUsage,RequireClientSecret,RequireConsent,RequirePkce,SlidingRefreshTokenLifetime,UpdateAccessTokenClaimsOnRefresh")] Client client) { if (ModelState.IsValid) { _context.Add(client); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(client)); }
public async Task <IActionResult> Create([Bind("ID,FirstName,LastName,Email,Password,CreditCard,CarNumber,CarType,Address,PhoneNumber,Balance")] GeneralUser generalUser) { if (ModelState.IsValid) { _context.Add(generalUser); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(generalUser)); }
public async Task <IActionResult> Create([Bind("idPatients,namePatients,phonePatients,gender,health_condition,doctor_id,nurse_id,created")] Patients patients) { if (ModelState.IsValid) { _context.Add(patients); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(patients)); }
public async Task <IActionResult> Create([Bind("Id,Description,DisplayName,Enabled,Name")] ApiResource apiResource) { if (ModelState.IsValid) { _context.Add(apiResource); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(apiResource)); }
public async Task <IActionResult> Create([Bind("idSpecialite,nameSpecialite")] Specialites specialites) { if (ModelState.IsValid) { _context.Add(specialites); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(specialites)); }
public async Task <IActionResult> Create([Bind("Id,AccessFailedCount,ConcurrencyStamp,Email,EmailConfirmed,LockoutEnabled,LockoutEnd,NormalizedEmail,NormalizedUserName,PasswordHash,PhoneNumber,PhoneNumberConfirmed,SecurityStamp,TwoFactorEnabled,UserName,Deleted,DeletedByUserId,DeletedDate,FirstName,LastName")] AspNetUser aspNetUser) { if (ModelState.IsValid) { _context.Add(aspNetUser); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewData["DeletedByUserId"] = new SelectList(_context.AspNetUsers, "Id", "Id", aspNetUser.DeletedByUserId); return(View(aspNetUser)); }
public async Task <IActionResult> Create([Bind("Id,Name,Price,IsDelete")] Sevice sevice) { if (ModelState.IsValid) { _context.Add(sevice); await _context.SaveChangesAsync(); Message = "Successfully create sevice"; return(RedirectToAction(nameof(Index))); } return(View(sevice)); }
public async Task <IActionResult> Create([Bind("Id,Title,IsDelete")] Category category) { if (ModelState.IsValid) { _context.Add(category); await _context.SaveChangesAsync(); Message = "Successfully create rooms"; return(RedirectToAction(nameof(Index))); } return(View(category)); }
public async Task <IActionResult> Create([Bind("Id,Title,Age,Describe,IsDelete")] Mac mac) { if (ModelState.IsValid) { _context.Add(mac); await _context.SaveChangesAsync(); Message = "Successfully create mac"; return(RedirectToAction(nameof(Index))); } return(View(mac)); }
public async Task <IActionResult> Create([Bind("IdMedConv,NomMedConv,PrenomMedConv,Email,Jours_Usine,PlageHoraire,Honoraire_seance,MobielMedConv,idSpecialite")] MedecinConventionne medecinConventionne) { if (ModelState.IsValid) { _context.Add(medecinConventionne); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["idSpecialite"] = new SelectList(_context.Specialites, "idSpecialite", "nameSpecialite", medecinConventionne.idSpecialite); return(View(medecinConventionne)); }
public async Task <IActionResult> Create([Bind("Name,Info,Specification,Rating,SubcategoryId")] Product product, string[] selectedSellers) { /*if (ModelState.IsValid) * { * _context.Add(product); * await _context.SaveChangesAsync(); * return RedirectToAction(nameof(Index)); * } * ViewData["SubcategoryId"] = new SelectList(_context.Set<Subcategory>(), "Id", "Name", product.SubcategoryId); * return View(product);*/ if (selectedSellers != null) { product.SellerProducts = new List <SellerProduct>(); foreach (var seller in selectedSellers) { var sellerToAdd = new SellerProduct { ProductId = product.Id, SellerId = int.Parse(seller) }; product.SellerProducts.Add(sellerToAdd); } } try { if (ModelState.IsValid) { var products = _context.Products.Where(p => p.Name == product.Name).Where(p => p.Info == product.Info).Where(p => p.Specification == product.Specification).FirstOrDefault(); if (products != null) { ModelState.AddModelError(string.Empty, "This product already exists"); return(RedirectToAction("Create", "Products", new { subcategoryId = product.SubcategoryId })); } else { _context.Add(product); await _context.SaveChangesAsync(); //return RedirectToAction(nameof(Index)); return(RedirectToAction("Index", "Products", new { Id = product.SubcategoryId, name = _context.Subcategories.Where(c => c.Id == product.SubcategoryId).FirstOrDefault().Name })); } } } catch (DbUpdateException /* ex */) { //Log the error (uncomment ex variable name and write a log. ModelState.AddModelError("", "Unable to save changes. " + "Try again, and if the problem persists " + "see your system administrator."); } //return View(product); PopulateAssignedSellerData(product); return(RedirectToAction("Index", "Products", new { Id = product.SubcategoryId, name = _context.Subcategories.Where(c => c.Id == product.SubcategoryId).FirstOrDefault().Name })); }
public async Task <IActionResult> Create([Bind("Id,ClientId,Description,Expiration,Type,Value")] ClientSecret clientSecret) { if (ModelState.IsValid) { clientSecret.Value = clientSecret.Value.Sha256(); _context.Add(clientSecret); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewData["ClientId"] = new SelectList(_context.Clients, "Id", "ClientId", clientSecret.ClientId); return(View(clientSecret)); }
public async Task <IActionResult> Register(RegisterViewModel model) { Customers addCustomers = new Customers(); addCustomers.EmailOfCustomer = model.Email; addCustomers.Citi = model.Citi; addCustomers.NameOfComany = model.NameOfComany; addCustomers.NIP = model.NIP; addCustomers.Street = model.Street; addCustomers.PhoneNumber = model.PhoneNumber; addCustomers.NameOfCustomer = model.NameOfCustomer; _context.Add(addCustomers); try { _context.SaveChanges(); } catch (DbUpdateException) { return(Content("Brak dostepu do Bazy")); } RegisterModel addNewUser = new RegisterModel(); addNewUser.Email = model.Email; addNewUser.Login = model.Login; addNewUser.RepeatPassword = model.RepeatPassword; addNewUser.Password = model.Password; if (ModelState.IsValid) { var identity = new UserModel(addNewUser.Login); identity.Email = addNewUser.Email; identity.CustomersID = addCustomers.Id; var result = await _signInManager.UserManager.CreateAsync(identity, addNewUser.Password); if (result.Succeeded) { await _signInManager.PasswordSignInAsync(model.Login, model.Password, false, false); return(RedirectToAction("Index", "Account")); } foreach (var error in result.Errors) { ModelState.AddModelError("", error.Description); } } return(View()); }
public IActionResult AddRoom(RoomDescriptionModel roomDescription) { var listFromDataBase = _context.RoomDescriptionModels .Where(x => x.NameOfRoom == roomDescription.NameOfRoom) .ToList(); //for (int i = 0; i < listFromDataBase.Count; i++) //{ // string name = listFromDataBase[i].NameOfRoom; // if (name == roomDescription.NameOfRoom) // { // TempData["Massege"] = "Sala o podanej nazwie juz istneje"; // return AddRoom(); // } //} //if (listFromDataBase.Contains(name)) //{ //} //if (string.IsNullOrEmpty(roomDescription.NameOfRoom)) //{ // return Content("Prosze podać nazwę sali"); //} if (ModelState.IsValid) { _context.Add(roomDescription); try { _context.SaveChanges(); } catch (DbUpdateException) { if (roomDescription.Id != default(int)) { roomDescription.Id = default(int); _context.SaveChanges(); } } } return(AddRoom()); }
public IActionResult RentRoomReservationTerms(string term, string room) { RoomRentModel myRentModel = new RoomRentModel(); var myRoom = _context.RoomDescriptionModels.Where(x => x.NameOfRoom == room) .Select(i => i.Id).ToArray(); string[] dateFromViev = term.Split(); int temp = Int32.Parse(dateFromViev[1]); var temp2 = HttpContext.User.Identity.Name; var temp3 = _context.UserModels.Where(x => x.UserName == temp2) .Select(i => i.CustomersID).ToArray(); var isItFree = _context.RoomRent.Where(x => x.DateOfEvent == dateFromViev[0]) .Where(d => d.HourOfBeginEvent == dateFromViev[1]).ToList(); if (isItFree.Count == 0) { temp = temp + 1; myRentModel.StateOfReservation = "New"; myRentModel.DateOfEvent = dateFromViev[0]; myRentModel.HourOfBeginEvent = dateFromViev[1]; myRentModel.HourOfEndEvent = temp.ToString(); myRentModel.CreatedByUser = HttpContext.User.Identity.Name; myRentModel.CreatedByChanel = "Internet"; myRentModel.CreatedDate = DateTime.Now.ToString("d"); myRentModel.NameOfEvent = "Cos Tam"; myRentModel.CustomersId = temp3[0]; myRentModel.RoomDescriptionModelId = myRoom[0]; myRentModel.OwnerOfEvent = HttpContext.User.Identity.Name; _context.Add(myRentModel); try { _context.SaveChanges(); } catch (DbUpdateException) { return(Content("Brak dostepu do Bazy")); } } else { } return(RedirectToAction("Index", "Account")); }
public async Task <IActionResult> Create([Bind("Id,Name,Row,Col,RoleId")] Room room) { if (ModelState.IsValid) { Role role = new Role(); int idem = _context.Rooms.Count() + 1; room.Name = "Room " + idem; role.Name = "Manager " + room.Name; await RoleMgr.CreateAsync(role); room.RoleId = role.Id; _context.Add(room); await _context.SaveChangesAsync(); Message = "Successfully create rooms"; return(RedirectToAction(nameof(Index))); } ViewData["RoleId"] = new SelectList(_context.Staffs, "Id", "RoleId", room.Role.Name); return(View(room)); }
public async Task <IActionResult> Create([Bind("Name,Adress,Rating")] Seller seller, string[] selectedProducts) { /*if (ModelState.IsValid) * { * _context.Add(seller); * await _context.SaveChangesAsync(); * return RedirectToAction(nameof(Index)); * } * return View(seller);*/ if (selectedProducts != null) { seller.SellerProducts = new List <SellerProduct>(); foreach (var product in selectedProducts) { var productToAdd = new SellerProduct { SellerId = seller.Id, ProductId = int.Parse(product) }; seller.SellerProducts.Add(productToAdd); } } if (ModelState.IsValid) { var sellers = _context.Sellers.Where(s => s.Name == seller.Name).Where(s => s.Rating == seller.Rating).Where(s => s.Adress == seller.Adress).FirstOrDefault(); if (sellers != null) { ModelState.AddModelError(string.Empty, "This seller already exists"); //return View(seller); } else { _context.Add(seller); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } } PopulateAssignedProductData(seller); return(View(seller)); }
public async Task <IActionResult> Register([FromBody] RegisterViewModel model) { try { var user = new IdentityUser { UserName = model.Email.TrimAndToLower(), Email = model.Email.TrimAndToLower() }; IdentityResult result = null; using (var transaction = await _dbContext.Database.BeginTransactionAsync()) { try { result = await _userManager.CreateAsync(user, model.Password); if (!result.Succeeded) { return(BadRequest(result.ToErrorList())); } _dbContext.Add(new UserInfo(user.Id, user.Email).SetDefaultAddress().SetName(model.Name)); await _dbContext.SaveChangesAsync(); transaction.Commit(); return(Ok()); } catch (System.Exception e) { transaction.Rollback(); throw; } } } catch (Exception) { throw; } }
public IActionResult CreateOrEdit([Bind("Name,Id,Number")] Test test) { if (ModelState.IsValid) { try { if (test.Id == 0) { _context.Add(test); } else { _context.Update(test); } _context.SaveChanges(); } catch (Exception) { } } return(View("Index")); }
public void Add(Review review) { db.Add(review); }