Example #1
0
        public ActionResult Save(StaffAddress staffAddress)
        {
            if (!ModelState.IsValid)
            {
                var viewModel = new StaffAddressViewModel
                {
                    StaffAddress = staffAddress,
                    AddressTypes = _context.AddressTypes.ToList()
                };
                return(View("StaffAddressForm", viewModel));
            }
            if (staffAddress.Id == 0)
            {
                _context.StaffAddresses.Add(staffAddress);
            }

            else
            {
                var staffAddressInDb = _context.CustomerAddress.Single(m => m.Id == staffAddress.Id);
                staffAddressInDb.AddressTypeId = staffAddress.AddressTypeId;
                staffAddressInDb.StreetAddress = staffAddress.StreetAddress;
                staffAddressInDb.Address2      = staffAddress.Address2;
                staffAddressInDb.City          = staffAddress.City;
                staffAddressInDb.State         = staffAddress.State;
                staffAddressInDb.ZipCode       = staffAddress.ZipCode;
            }
            _context.SaveChanges();
            return(RedirectToAction("Details", "Staff", new { id = staffAddress.StaffId }));
        }
        public async Task <IActionResult> Edit(int id, [Bind("staffID,AddressID")] StaffAddress staffAddress) // Binding the id to the staffaddress so it can be recalled
        {
            if (id != staffAddress.staffID)                                                                   //it makes sure that the ID is related to the staff address
            {
                return(NotFound());                                                                           // throws an error if it isnt
            }

            if (ModelState.IsValid) // if it is correctly binded then carry on to this
            {
                try
                {
                    _context.Update(staffAddress);     //updates the database
                    await _context.SaveChangesAsync(); //wait until it comes back
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!StaffAddressExists(staffAddress.staffID)) // if it already exists within the db then return an error
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index))); // if it works well - go back to the index
            }
            ViewData["AddressID"] = new SelectList(_context.Addresses, "AddressID", "AddressID", staffAddress.AddressID);
            ViewData["staffID"]   = new SelectList(_context.Staffs, "staffID", "staffID", staffAddress.staffID);
            return(View(staffAddress));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            StaffAddress staffAddress = db.StaffAddresses.Find(id);

            db.StaffAddresses.Remove(staffAddress);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public ActionResult Edit([Bind(Include = "StaffAddressID,StaffAddressName,HomeAddress,StaffID,PostalAddress,City,CountryID")] StaffAddress staffAddress)
 {
     if (ModelState.IsValid)
     {
         db.Entry(staffAddress).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CountryID = new SelectList(db.Countries, "CountryID", "CountryName", staffAddress.CountryID);
     ViewBag.StaffID   = new SelectList(db.Staffs, "StaffID", "FirstName", staffAddress.StaffID);
     return(View(staffAddress));
 }
        public async Task <IActionResult> Create([Bind("staffID,AddressID")] StaffAddress staffAddress)  // creating the compound key
        {
            if (ModelState.IsValid)
            {
                _context.Add(staffAddress);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["AddressID"] = new SelectList(_context.Addresses, "AddressID", "AddressID", staffAddress.AddressID);
            ViewData["staffID"]   = new SelectList(_context.Staffs, "staffID", "staffID", staffAddress.staffID);
            return(View(staffAddress));
        }
        // GET: StaffAddresses/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            StaffAddress staffAddress = db.StaffAddresses.Find(id);

            if (staffAddress == null)
            {
                return(HttpNotFound());
            }
            return(View(staffAddress));
        }
        private void BtnRefesh_Click(object sender, RoutedEventArgs e)
        {
            StaffName.Clear();
            StaffAddress.Clear();
            PhoneName.Clear();
            BirthDate.Text = "";
            comboPosition.SelectedIndex = -1;
            combosex.SelectedIndex      = -1;
            BitmapImage image = new BitmapImage();

            image.BeginInit();
            image.UriSource = new Uri("pack://application:,,/Images/Image.png");
            image.EndInit();
            imgStaff.Source = image;
            imgStaff.Tag    = null;
        }
        // GET: StaffAddresses/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            StaffAddress staffAddress = db.StaffAddresses.Find(id);

            if (staffAddress == null)
            {
                return(HttpNotFound());
            }
            ViewBag.CountryID = new SelectList(db.Countries, "CountryID", "CountryName", staffAddress.CountryID);
            ViewBag.StaffID   = new SelectList(db.Staffs, "StaffID", "FirstName", staffAddress.StaffID);
            return(View(staffAddress));
        }
Example #9
0
 public void FormControls(string CLR)
 {
     if (CLR == "CLR")
     {
         StaffID.Clear();
         StaffName.Clear();
         StaffType.Text = "Select";
         StaffAddress.Clear();
         StaffCity.Clear();
         StaffContact.Clear();
         StaffID.Enabled      = false;
         StaffName.Enabled    = false;
         StaffType.Enabled    = false;
         StaffAddress.Enabled = false;
         StaffCity.Enabled    = false;
         StaffContact.Enabled = false;
         btnsave.Enabled      = false;
         btnedit.Enabled      = false;
         btndelete.Enabled    = false;
         btnadd.Enabled       = true;
         btnfind.Enabled      = true;
         Left1.Enabled        = false;
         Right1.Enabled       = false;
     }
     if (CLR == "Save")
     {
         btnsave.Enabled      = true;
         btnadd.Enabled       = false;
         btnfind.Enabled      = false;
         btndelete.Enabled    = false;
         btnedit.Enabled      = false;
         StaffName.Enabled    = true;
         StaffType.Enabled    = true;
         StaffAddress.Enabled = true;
         StaffCity.Enabled    = true;
         StaffContact.Enabled = true;
         StaffName.Focus();
     }
 }
Example #10
0
 private void ChangeStaffAddress(StaffAddressDto dto, Staff staff, StaffAddress staffAddress)
 {
     RemoveStaffAddress(dto, staff, staffAddress);
     AddStaffAddress(dto, staff);
 }
Example #11
0
 private void RemoveStaffAddress(StaffAddressDto dto, Staff staff, StaffAddress staffAddress)
 {
     staff.RemoveAddress(staffAddress);
 }