public static void InsertTable(Item_transcation_inventory item) { SampleDBContext db = new SampleDBContext(); db.Item_transcation_inventory.Add(item); db.SaveChanges(); }
public IActionResult Put(int EmpId, [FromBody] Employee employees) { SampleDBContext responseObj = new SampleDBContext(); Response <List <Employee> > employeeObj = new Response <List <Employee> >(); // List<Employee> Object1 = new List<Employee>(); try { using (var test = new SampleDBContext()) { var newRecord = test.Employee.Where(t => t.EmpId == EmpId).FirstOrDefault(); // var newRecord = (from c in test.Employee where c.Equals(EmpId) select c).ToList(); if (newRecord != null) { newRecord.Name = employees.Name; newRecord.City = employees.City; newRecord.DeptId = employees.DeptId; //test.Employee.Update(employees); test.SaveChanges(); } return(Ok(employeeObj)); } } catch (Exception ex) { //return NotFound(); employeeObj.Status = HttpStatusCode.NotFound; employeeObj.Message = "you have given wrong input"; return(NotFound(employeeObj)); } }
public IActionResult Insert([FromBody] Employee employee) { SampleDBContext resposeObj = new SampleDBContext(); Response <List <Employee> > employeeObj = new Response <List <Employee> >(); List <Employee> Object1 = new List <Employee>(); try { using (var test = new SampleDBContext()) { test.Employee.Add(employee); test.SaveChanges(); employeeObj.Status = HttpStatusCode.OK; employeeObj.Message = "record displayed successfully"; } return(Ok(employeeObj)); } catch (Exception ex) { employeeObj.Status = HttpStatusCode.NotFound; employeeObj.Message = "you have given wrong input"; return(NotFound(employeeObj)); } }
public IActionResult Delete(int EmpId) { SampleDBContext responseObj = new SampleDBContext(); Response <List <Employee> > employeeObj = new Response <List <Employee> >(); try { using (var test = new SampleDBContext()) { Employee employee = new Employee(); var record = test.Employee.Where(t => t.EmpId == EmpId).FirstOrDefault(); test.Employee.Remove(record); test.SaveChanges(); return(Ok(responseObj)); } } catch (Exception ex) { //return NotFound(); employeeObj.Status = HttpStatusCode.NotFound; employeeObj.Message = "you have given wrong input"; return(NotFound(employeeObj)); } }
public void Setup() { _context = TestHelper.GetContexto(); _fabricanteRepository = TestHelper.CriarRepositorio <Fabricante>(_context); _ramoRepository = TestHelper.CriarRepositorio <RamoAtividade>(_context); _produtoRepository = TestHelper.CriarRepositorio <Produto>(_context); }
/// <summary> /// Get all employees data from the database /// </summary> /// <returns>List<Employees></returns> public List <Employee> GetEmployees() { var context = new SampleDBContext(); List <Employee> employeesList = context.Employees.ToList(); return(employeesList); }
// GET: Home public ActionResult Index() { SampleDBContext db = new SampleDBContext(); List <Employee> employee = db.Employees.ToList(); return(View(employee)); }
public ActionResult Edit(int id) { SampleDBContext db = new SampleDBContext(); Employee employees = db.Employees.Single(x => x.Id == id); return(View(employees)); }
public IActionResult Patch(int EmpId, /*string empname,*/ [FromBody] Employee employee) { Response <List <Employee> > employeeObj = new Response <List <Employee> >(); SampleDBContext responseObj = new SampleDBContext(); try { using (var test = new SampleDBContext()) { var updateRecord = test.Employee.FirstOrDefault(t => t.EmpId == EmpId); updateRecord.Name = employee.Name; // Testcase1: If user try to update city column, there will be mismatch error with the body input test.SaveChanges(); employeeObj.Status = HttpStatusCode.OK; employeeObj.Message = "record updated successfully"; return(Ok(employeeObj)); } } catch { employeeObj.Status = HttpStatusCode.NotFound; employeeObj.Message = "you have given wrong input"; return(NotFound(employeeObj)); } }
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { SampleDBContext sampleDBContext = new SampleDBContext(); return((from g in sampleDBContext.Groups where g.GroupName == (string)value select g.GroupID).FirstOrDefault()); }
public static void DeleteTable(Item_transcation_inventory item) { SampleDBContext db = new SampleDBContext(); Item_transcation_inventory i = db.Item_transcation_inventory.Find(item.SN); db.Item_transcation_inventory.Remove(i); db.SaveChanges(); }
public void AddUser(User user) { user.Password = "******"; //Default password for all the users using (var dataContext = new SampleDBContext()) { dataContext.Users.Add(user); dataContext.SaveChanges(); } }
/// <summary> /// コンストラクタ /// </summary> /// <param name="context"></param> public Logic(SampleDBContext context = null) { if (context == null) { context = new SampleDBContext(); } this.sampleDBContext = context; }
/// <summary> /// Delete Employee by Id /// </summary> /// <param name="employeeId"></param> public void DeleteEmployee(int employeeId) { using (var context = new SampleDBContext()) { var emp = context.Employees.Where(e => e.Id == employeeId).FirstOrDefault(); context.Employees.Remove(emp); context.SaveChanges(); } }
public IEnumerable <User> GetAll() { List <User> _users = new List <User>(); using (var dataContext = new SampleDBContext()) { _users = dataContext.Users.Include(u => u.Roles).ToList(); } return(_users); }
public static user GetUserByEmail(string email, SampleDBContext DBContext = null) { if (DBContext == null) { DBContext = new SampleDBContext(); } user user = DBContext.users.FirstOrDefault(x => x.email == email); return(user); }
public User GetById(int id) { List <User> _users = new List <User>(); using (var dataContext = new SampleDBContext()) { _users = dataContext.Users.Include(u => u.Roles).ToList(); } return(_users.FirstOrDefault(x => x.UserId == id)); }
public static void GetEntityMappingMetadta() { SampleDBContext g = new SampleDBContext(); Type type = typeof(SampleDBContext); var entityData = GetEntitywithProperties(type); var mappingData = GetFluentAPImetdata(type, g); }
public void Delete(User user) { using (var dataContext = new SampleDBContext()) { dataContext.Roles.RemoveRange(dataContext.Roles.Where(x => x.UserId == user.UserId)); dataContext.SaveChanges(); dataContext.Entry(user).State = EntityState.Deleted; dataContext.SaveChanges(); } }
public static Boolean SetupUserToForgotPasswordState(user user, SampleDBContext DBContext = null) { if (DBContext == null) { DBContext = new SampleDBContext(); } // update user reset_password_token user.reset_password_token = EncryptoService.GetSpecificLengthRandomString(64, true); user.reset_experation = DateTime.Now.AddMinutes(10); return(DBContext.SaveChanges() == 1); }
public ActionResult List() { SampleDBContext db = new SampleDBContext(); var model = new Container() { Id = Guid.NewGuid(), items = db.Item_transcation_inventory.ToList() }; return(Json(model, JsonRequestBehavior.AllowGet)); }
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if (value != null) { SampleDBContext sampleDBContext = new SampleDBContext(); return((from g in sampleDBContext.Groups where g.GroupID == (int)value select g.GroupName).FirstOrDefault()); } else { return(""); } }
public static SampleDBContext GetContexto() { var connectionString = "Data Source=localhost;Initial Catalog=DDDSampleTest;Integrated Security=True;Connect Timeout=15;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False; MultipleActiveResultSets=true"; var options = new DbContextOptionsBuilder <SampleDBContext>() .UseSqlServer(connectionString) .Options; var _context = new SampleDBContext(options); return(_context); }
public void Update(User user) { using (var dataContext = new SampleDBContext()) { dataContext.Roles.RemoveRange(dataContext.Roles.Where(x => x.UserId == user.UserId)); dataContext.SaveChanges(); if (user.Password == null) { var userDB = GetById(user.UserId); user.Password = userDB.Password; } dataContext.Users.Update(user); dataContext.SaveChanges(); } }
public ActionResult Index() { SampleDBContext db = new SampleDBContext(); List <SelectListItem> listSelectListItem = new List <SelectListItem>(); foreach (City city in db.Cities) { listSelectListItem.Add(new SelectListItem { Text = city.Name, Value = city.ID.ToString(), Selected = city.IsSelected }); } CitiesViewModel citiesViewModel = new CitiesViewModel(); citiesViewModel.Cities = listSelectListItem; return(View(citiesViewModel)); }
public ObjectResult Get(int EmpId) { SampleDBContext sampleDBContext = new SampleDBContext(); Response <List <Employee> > responseObj = new Response <List <Employee> >(); List <Employee> employees = null; // var ids = employees.Select(x => x.EmpId); try { using (var test = new SampleDBContext()) { employees = (from c in test.Employee where c.EmpId.Equals(EmpId) select c).ToList(); } if (employees.Count != 0) { responseObj.Status = HttpStatusCode.OK; responseObj.Message = "record displayed successfully"; return(Ok(employees)); } else { //responseObj.Status = HttpStatusCode.NotFound; //responseObj.Message = "No records found with the given Id"; //throw new NullReferenceException(HttpStatusCode.NotFound); //var message = new HttpResponseMessage(HttpStatusCode.BadRequest) //{ // Content = new StringContent("We cannot use IDs greater than 100.") //}; responseObj.Status = HttpStatusCode.NotFound; responseObj.Message = "Employee ID not found"; return(NotFound(responseObj)); //throw new Exception(message.ToString()); } } catch (Exception ex) { responseObj.Status = HttpStatusCode.BadRequest; responseObj.Message = ex.Message; return(BadRequest(responseObj)); //throw new NullReferenceException(HttpStatusCode.NotFound); } }
public ActionResult Confirm(Guid id) { Container container = InventoryHelper.CheckAndGetContainerModel(id); //clear Table //DbHelper.DeleteSN(container.items); //insert data to into database DbHelper.InsertSN(container.items); //Display data from database SampleDBContext db = new SampleDBContext(); var model = new Container() { Id = Guid.NewGuid(), items = db.Item_transcation_inventory.ToList() }; return(View(model)); //return View(); }
public AuthenticateResponse Authenticate(AuthenticateRequest model) { List <User> _users = new List <User>(); using (var dataContext = new SampleDBContext()) { _users = dataContext.Users.Include(u => u.Roles).ToList(); } var user = _users.SingleOrDefault(x => x.Username == model.Username && x.Password == model.Password); // return null if user not found if (user == null) { return(null); } // authentication successful so generate jwt token var token = generateJwtToken(user); return(new AuthenticateResponse(user, token)); }
public ActionResult Edit(Employee employee) { if (ModelState.IsValid) { SampleDBContext db = new SampleDBContext(); Employee employeeFromDB = db.Employees.Single(x => x.Id == employee.Id); // Populate all the properties except EmailAddrees employeeFromDB.FullName = employee.FullName; employeeFromDB.Gender = employee.Gender; employeeFromDB.Age = employee.Age; employeeFromDB.HireDate = employee.HireDate; employeeFromDB.Salary = employee.Salary; employeeFromDB.PersonalWebSite = employee.PersonalWebSite; db.Entry(employeeFromDB).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Details", new { id = employee.Id })); } return(View(employee)); }
public static user Register(string email, string password, SampleDBContext DBContext = null) { if (DBContext == null) { DBContext = new SampleDBContext(); } SaltedPassword saltedPassword = EncryptoService.GenerateSaltedHash(64, password); user newUser = new user() { email = email, salt = saltedPassword.Salt, password = saltedPassword.Hash, created_at = DateTime.Now }; try { DBContext.users.Add(newUser); DBContext.SaveChanges(); } catch (Exception ex) { throw new Exception(ex.ToString()); } return(newUser); }
// // GET: /Home/ public ActionResult Index() { /* // Connect to the database SampleDBContext db = new SampleDBContext(); // Retrieve departments, and build SelectList ViewBag.Departments = new SelectList(db.Departments, "Id", "Name"); return View(); * */ SampleDBContext db = new SampleDBContext(); List<SelectListItem> selectListItems = new List<SelectListItem>(); foreach (Department department in db.Departments) { SelectListItem selectListItem = new SelectListItem { Text = department.Name, Value = department.Id.ToString(), Selected = department.IsSelected.HasValue ? department.IsSelected.Value : false }; selectListItems.Add(selectListItem); } ViewBag.Departments = selectListItems; return View(); }