public void Should_Success_Read_Data() { ProjectDbContext projectDbContext = MemoryDbHelper.GetDB(Helper.GetCurrentMethod(ENTITY)); TFacade tFacade = (TFacade)Activator.CreateInstance(typeof(TFacade), projectDbContext); projectDbContext.Add(dataUtil.GetModelData()); projectDbContext.Add(dataUtil.GetModelData()); projectDbContext.SaveChanges(); Assert.Equal(2, tFacade.Read().Count); }
public ActionResult Create(Project project) { // Save the project in the database and redirect to index context.Add(project); context.SaveChanges(); return(RedirectToAction("Index")); }
public IActionResult Create(Department department) { if (ModelState.IsValid && !IsDeptExists(department.Id)) { _context.Add(department); _context.SaveChanges(); } return(RedirectToAction("Index")); }
public async Task <IActionResult> Create([Bind("Id,ProductName,Price")] Product product) { if (ModelState.IsValid) { _context.Add(product); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(product)); }
public async Task <IActionResult> Create([Bind("Id,Photo,Link")] Social social) { if (ModelState.IsValid) { _context.Add(social); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(social)); }
public async Task <IActionResult> Create([Bind("Id,Name,Abrv")] VehicleMake vehicleMake) { if (ModelState.IsValid) { DbContext.Add(vehicleMake); await DbContext.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(vehicleMake)); }
public async Task <IActionResult> Create([Bind("Id,ClientName")] Client client) { if (ModelState.IsValid) { _context.Add(client); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(client)); }
public async Task <IActionResult> Create([Bind("Id,Date,Discount,ExpiryDate,Client")] OfferHeader offerHeader) { if (ModelState.IsValid) { _context.Add(offerHeader); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(offerHeader)); }
public async Task <IActionResult> Create([Bind("Id,Name,Description,Estado")] Category category) { if (ModelState.IsValid) { _context.Add(category); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(category)); }
public async Task <IActionResult> Create([Bind("Id,Email,PhoneNumber")] Contact contact) { if (ModelState.IsValid) { _context.Add(contact); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(contact)); }
public async Task <IActionResult> Create([Bind("ID,EmpKey,ProjKey,authorized_assignment")] ProjectAssignment projectAssignment) { if (!ModelState.IsValid) { return(View(projectAssignment)); } _context.Add(projectAssignment); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> Create([Bind("Id,Name")] Specification specification) { if (ModelState.IsValid) { _context.Add(specification); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(specification)); }
public async Task <IActionResult> Create([Bind("Id,Title,PublishedDate,Image")] News news) { if (ModelState.IsValid) { _context.Add(news); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(news)); }
public async Task <IActionResult> Create([Bind("ID,ProjectId,AssignedBy,WBSSummary,WBSHours,StartDate,EndDate,WBSCost")] WBSModel wBSModel) { if (ModelState.IsValid) { _context.Add(wBSModel); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(wBSModel)); }
public async Task <IActionResult> Create([Bind("DailyTaskId,Description")] DailyTask dailyTask) { if (ModelState.IsValid) { _context.Add(dailyTask); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(dailyTask)); }
public async Task <IActionResult> Create([Bind("Id,First_name,Last_name,Age,Email,Ssn")] Owner owner) { if (ModelState.IsValid) { _context.Add(owner); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(owner)); }
public async Task <IActionResult> Create([Bind("Id,Name,Email,Building_type,Constructed_date,Stories,OwnerId")] Building building) { if (ModelState.IsValid) { _context.Add(building); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["OwnerId"] = new SelectList(_context.Owners, "Id", "Email", building.OwnerId); return(View(building)); }
public async Task <IActionResult> Create([Bind("Id,Name,CategoryId")] SubCategory subCategory) { if (ModelState.IsValid) { _context.Add(subCategory); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["CategoryId"] = new SelectList(_context.Categories, "Id", "Name", subCategory.CategoryId); return(View(subCategory)); }
public async Task <IActionResult> Create([Bind("Id,Name,MainPhoto,Price,SalePercent,GuaranteeDate,GuaranteePrice,Condition,ShipDate,ShipPrice,TestDate,Specification,SubCategoryItemsId,IsInBasket")] Product product) { if (ModelState.IsValid) { _context.Add(product); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["SubCategoryItemsId"] = new SelectList(_context.SubCategoryItems, "Id", "Name", product.SubCategoryItemsId); return(View(product)); }
public async Task <IActionResult> Create([Bind("Id,Name,MarkaId")] Model model) { if (ModelState.IsValid) { _context.Add(model); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["MarkaId"] = new SelectList(_context.Markas, "Id", "Name", model.MarkaId); return(View(model)); }
public async Task <IActionResult> Create([Bind("Id,Name,SubCategoryItemsId")] Marka marka) { if (ModelState.IsValid) { _context.Add(marka); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["SubCategoryItemsId"] = new SelectList(_context.SubCategoryItems, "Id", "Name", marka.SubCategoryItemsId); return(View(marka)); }
public async Task <IActionResult> Create([Bind("Id,Path,ProductId")] Photo photo) { if (ModelState.IsValid) { _context.Add(photo); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["ProductId"] = new SelectList(_context.Products, "Id", "MainPhoto", photo.ProductId); return(View(photo)); }
public bool Add(TipoTrabajo model) { try { _projectDbContext.Add(model); _projectDbContext.SaveChanges(); }catch (Exception e) { return(false); } return(true); }
public async Task <IActionResult> Create([Bind("Value,ProductId,SpecificationId")] ProductSpec productSpec) { if (ModelState.IsValid) { _context.Add(productSpec); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["ProductId"] = new SelectList(_context.Products, "Id", "Name", productSpec.ProductId); ViewData["SpecificationId"] = new SelectList(_context.Specification, "Id", "Name", productSpec.SpecificationId); return(View(productSpec)); }
public bool Add(Categoria model) { try { _ProjectDbContext.Add(model); _ProjectDbContext.SaveChanges(); } catch (Exception e) { return(false); } return(true); }
public IActionResult Create(Student student) { Student newStudent = new Student(); if (ModelState.IsValid && !IsStudentExists(student.Id)) { newStudent.Name = student.Name; newStudent.RegistrationNo = student.RegistrationNo; newStudent.Department = _context.Departments.Find(student.DepartmentId); _context.Add(newStudent); _context.SaveChanges(); } return(RedirectToAction("Index")); }
public void Should_Return_Bad_Request_Create_Data() { ProjectDbContext projectDbContext = MemoryDbHelper.GetDB(Helper.GetCurrentMethod(ENTITY)); Mock <IBuyerFacade> mockBuyerFacade = new Mock <IBuyerFacade>(); mockBuyerFacade.Setup(p => p.Create(It.IsAny <Buyer>())) .Returns(0); Mock <IServiceProvider> mockServiceProvider = new Mock <IServiceProvider>(); mockServiceProvider.Setup(p => p.GetService(typeof(IBuyerFacade))).Returns(mockBuyerFacade.Object); mockServiceProvider.Setup(p => p.GetService(typeof(ProjectDbContext))).Returns(projectDbContext); Mock <IMapper> mockMapper = new Mock <IMapper>(); mockMapper.Setup(p => p.Map <Buyer>(It.IsAny <BuyerViewModel>())) .Returns(buyerDataUtil.GetModelData()); BuyersController buyersController = new BuyersController(mockServiceProvider.Object, mockMapper.Object) { ControllerContext = new ControllerContext() { HttpContext = new DefaultHttpContext() } }; buyersController.ControllerContext.HttpContext.Request.Path = new PathString("/v1/unit-test"); //Add data for make it double projectDbContext.Add(buyerDataUtil.GetModelData()); projectDbContext.SaveChanges(); BuyerViewModel viewModel = buyerDataUtil.GetViewModelData(); IActionResult result = buyersController.Post(viewModel); Assert.Equal(HttpStatusCode.BadRequest, (HttpStatusCode)((BadRequestObjectResult)result).StatusCode); }
public int Create(TModel model) { BeforeCreate(model); _dbContext.Add(model); return(_dbContext.SaveChanges()); }
public Car Add(Car newCar) { _context.Add(newCar); _context.SaveChanges(); return(newCar); }
public async Task <IActionResult> CreateProject(ProjectCreateViewClass model, string returnUrl = null) { _logger.LogInformation("Creating Project"); // ViewData["ReturnUrl"] = returnUrl; // Check if Customer Exists var resultCheck = _appcontext.Users.Count(c => c.Email == model.CustEmail); // Check that model is good to go if (ModelState.IsValid && resultCheck > 0) { // Create New Project var project = new ProjectModel { ProjectName = model.ProjectName, Customer = model.CustEmail, ProjBudget = model.ProjBudget, ProjCurentCost = model.ProjCost, IsActive = model.ActiveProj, StartDate = model.ProjStart, EndDate = model.ProjEnd }; // Try to add to the database _context.Add(project); await _context.SaveChangesAsync(); // Start a Scope for this Project var projectContext = _context.ProjectModel.First(P => P.ProjectName == project.ProjectName && P.ProjBudget == project.ProjBudget); var defaultScope = new ScopeModel { ProjectId = projectContext.ID, ScopeVersion = 1, ScopeAuthor = "AUTHOR", ScopeGoals = "", ScopeExpectations = "", ScopeLimitations = "", ScopeManager = "", ScopePhase = "1", ScopeSummary = "", ScopeEndDate = DateTime.Today, ScopeStartDate = DateTime.Today }; _context.Scopes.Add(defaultScope); await _context.SaveChangesAsync(); // Redirect to the details if success. return(RedirectToAction("ProjectDetails", new { id = project.ID })); } if (resultCheck == 0) { _logger.LogCritical("Something went wrong in creating a new project."); ViewData["ErrorMsg"] = "Customer Email Doesn't Exist"; return(View(model)); } _logger.LogCritical("Something went wrong in creating a new project."); ViewData["ErrorMsg"] = "Server Side Error- Model State Invalid. Contact website manager."; return(View(model)); }