public async Task <IActionResult> Create([Bind("MemberID,MemberName,InductionDate,Age")] Member member) { if (ModelState.IsValid) { _context.Add(member); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(member)); }
public async Task <IActionResult> Create([Bind("Inv_ID,Inv_des,Inv_amount,Inv_date")] Invoice invoice) { if (ModelState.IsValid) { _context.Add(invoice); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(invoice)); }
public async Task <IActionResult> Create([Bind("Cus_ID,Cus_lname,Cus_fname,Cus_phone,Cus_email,Cus_street,Cus_city,Cus_pro,Cus_country,Inv_ID")] Customer customer) { if (ModelState.IsValid) { _context.Add(customer); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["Inv_ID"] = new SelectList(_context.Invoices, "Inv_ID", "Inv_ID", customer.Inv_ID); return(View(customer)); }
public async Task <IActionResult> Create([Bind("Emp_ID,Emp_lname,Emp_fname,Emp_phone,Emp_email,Cus_ID")] Employee employee) { if (ModelState.IsValid) { _context.Add(employee); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["Cus_ID"] = new SelectList(_context.Customers, "Cus_ID", "Cus_ID", employee.Cus_ID); return(View(employee)); }
// on creating makes sure sub company object is associated with company public bool Create(SubCompany subCompany) { try { _mgmtContext.Add(subCompany); _mgmtContext.SaveChanges(); return(true); } catch (DbUpdateException due) { Debug.WriteLine(due.Message); return(false); } }
public bool Create(Company company) { try { _mgmtContext.Add(company); _mgmtContext.SaveChanges(); return(true); } catch (Exception ex) { Debug.WriteLine("Message " + ex.Message); return(false); } }
public IActionResult Create([Bind("SerialNumber, Name, Stock")] Device device) { if (!_managementContext.Devices.Where(d => d.SerialNumber == device.SerialNumber).Any()) { if (ModelState.IsValid) { _managementContext.Add(device); _managementContext.SaveChanges(); return(RedirectToAction(nameof(Index))); } } else { ModelState.AddModelError("SerialNumber", "Serial number already in system"); } return(View(device)); }
public bool Create(Position position) { try { //checking if same position exists then return false to avoid duplicate creation of same position List <Position> positionsExist = _mgmtContext.Position.Where(p => p.Position_Type == position.Position_Type).ToList(); if (positionsExist.Count() == 1) { return(false); } _mgmtContext.Add(position); _mgmtContext.SaveChanges(); return(true); } catch (DbUpdateException due) { Debug.WriteLine(due.Message); return(false); } }
public bool CreateEmployee(EmployeeViewModel employeeViewModel) { try { HashSet <string> addressSet = null; HashSet <string> phoneNumberSet = null; Employee employee = new Employee(); employee.Name = employeeViewModel.EmployeeName; employee.Joined_Date = employeeViewModel.Joined_Date; // employee.Leave_Date = employeeViewModel.Joined_Date; employee.Salary = employeeViewModel.Salary; employee.SubCompany = _mgmtContext.SubCompany.Where(c => c.Id == employeeViewModel.SubCompanyId).ToList()[0]; employee.Positions = _mgmtContext.Position.Where(c => c.Id == employeeViewModel.PositionId).ToList()[0]; //checking optional phone numbers list is not null && empty //adding unique phone number only if (employeeViewModel.PhoneNumbers != null && employeeViewModel.PhoneNumbers.Count() > 0) { phoneNumberSet = new HashSet <string>(); foreach (string addr in employeeViewModel.PhoneNumbers) { if (!String.IsNullOrEmpty(addr)) { phoneNumberSet.Add(addr); } } } //checking optional address list is not null && empty //adding unique address only if (employeeViewModel.Addresses != null && employeeViewModel.Addresses.Count() > 0) { addressSet = new HashSet <string>(); foreach (string phn in employeeViewModel.Addresses) { if (!String.IsNullOrEmpty(phn)) { addressSet.Add(phn); } } } List <Phone> phones = new List <Phone>(); List <Address> addresses = new List <Address>(); Phone phone = new Phone(); phone.Phone_Number = employeeViewModel._PhoneNumber; phone.Employee = employee; phones.Add(phone); Address address = new Address(); address.Location = employeeViewModel._Address; address.Employee = employee; addresses.Add(address); if (phoneNumberSet != null) { foreach (string phn in phoneNumberSet) { phones.Add(new Phone { Phone_Number = phn, Employee = employee }); } } if (addressSet != null) { foreach (string addr in addressSet) { addresses.Add(new Address { Location = addr, Employee = employee }); } } employee.Addresses = addresses; employee.Phones = phones; _mgmtContext.Add(employee); _mgmtContext.SaveChanges(); return(true); } catch (Exception ex) { Console.WriteLine("Message " + ex.Message); return(false); } }