public ActionResult Create(DepartmentViewModel DeptVM)
        {
            if (ModelState.IsValid)
            {
                Department dept = new Department();
                dept.Name = DeptVM.Name;
                db.Departments.Add(dept);
                db.SaveChanges();

                DepartmentLocation deptLoc = new DepartmentLocation();
                deptLoc.DepartmentID = dept.DepartmentID;
                deptLoc.Location     = DeptVM.Location;
                db.DepartmentLocations.Add(deptLoc);
                db.SaveChanges();

                DepartmentManager deptMan = new DepartmentManager();
                deptMan.DepartmentID = dept.DepartmentID;
                deptMan.EmployeeId   = DeptVM.EmployeeId;
                deptMan.StartDate    = DeptVM.StartDate;
                db.DepartmentManagers.Add(deptMan);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(DeptVM));
        }
        public async Task <IActionResult> Edit(int id, [Bind("DepartmentID,LocationID")] DepartmentLocation departmentLocation)
        {
            if (id != departmentLocation.DepartmentID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(departmentLocation);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!DepartmentLocationExists(departmentLocation.DepartmentID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["DepartmentID"] = new SelectList(_context.Departments, "ID", "ID", departmentLocation.DepartmentID);
            ViewData["LocationID"]   = new SelectList(_context.Locations, "ID", "ID", departmentLocation.LocationID);
            return(View(departmentLocation));
        }
        private void frmEmergencyMaintenanceRequest_Load(object sender, EventArgs e)
        {
            Dictionary <string, string> tt = this.Tag as Dictionary <string, string>;

            //Fill data to group box Selected Asset
            lblAssetSNValue.Text   = tt["AssetSN"];
            lblAssetNameValue.Text = tt["AssetName"];
            Session2Entities db    = new Session2Entities();
            Asset            asset = (from x in db.Assets
                                      where x.AssetSN == lblAssetSNValue.Text && x.AssetName == lblAssetNameValue.Text
                                      select x).FirstOrDefault <Asset>();
            IEnumerable <EmergencyMaintenance> list_em = from x in db.EmergencyMaintenances
                                                         where x.AssetID == asset.ID
                                                         select x;

            DepartmentLocation departmentLocation = (from x in db.DepartmentLocations
                                                     where x.ID == asset.DepartmentLocationID
                                                     select x).FirstOrDefault <DepartmentLocation>();
            Department department = (from x in db.Departments
                                     where x.ID == departmentLocation.DepartmentID
                                     select x).FirstOrDefault <Department>();

            lblDepartmentValue.Text = department.Name;

            //Load combobox
            foreach (Priority temp in (from x in db.Priorities select x))
            {
                cbPriority.Items.Add(temp);
            }
            cbPriority.DisplayMember = "Name";
            cbPriority.ValueMember   = "ID";
            cbPriority.SelectedIndex = 0;
        }
        public async Task <IActionResult> Create([Bind("DepartmentID,LocationID")] DepartmentLocation departmentLocation)
        {
            if (ModelState.IsValid)
            {
                _context.Add(departmentLocation);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["DepartmentID"] = new SelectList(_context.Departments, "ID", "ID", departmentLocation.DepartmentID);
            ViewData["LocationID"]   = new SelectList(_context.Locations, "ID", "ID", departmentLocation.LocationID);
            return(View(departmentLocation));
        }
Exemplo n.º 5
0
        public dynamic Post([FromBody] object json2)
        {
            try
            {
                Dictionary <string, object> json = JsonConvert.DeserializeObject <Dictionary <string, object> >(json2.ToString());
                db = new WSC2019_SS1Entities();
                Models.Asset asset = new Models.Asset();
                asset.AssetName    = json["AssetName"].ToString();
                asset.AssetSN      = json["AssetSN"].ToString();
                asset.AssetGroupID = Convert.ToInt32(json["AssetGroupID"]);
                asset.Description  = json["Description"].ToString();
                asset.WarrantyDate = Convert.ToInt32(json["WarrantyDate"]);
                asset.EmployeeID   = Convert.ToInt32(json["EmployeeID"]);
                int locationid        = Convert.ToInt32(json["LocationID"]);
                int departmentid      = Convert.ToInt32(json["DepartmentID"]);
                DepartmentLocation dl = db.DepartmentLocations.Where(x => x.LocationID == locationid && x.DepartmentID == departmentid).SingleOrDefault();
                if (dl == null)
                {
                    dl.DepartmentID = departmentid;
                    dl.LocationID   = locationid;
                    dl.StartDate    = DateTime.Now;
                    db.DepartmentLocations.Add(dl);
                    db.SaveChanges();
                    dl = db.DepartmentLocations.Where(x => x.LocationID == locationid && x.DepartmentID == departmentid).SingleOrDefault();
                }
                asset.DepartmentLocationID = dl.ID;

                db.Assets.Add(asset);
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
            return("ok");
        }
        //=====================================================================


        // GET: Departments/Edit/5
        public ActionResult Edit(int?id)
        {
            Department         dept = db.Departments.Find(id);
            DepartmentManager  dm   = db.DepartmentManagers.Where(x => x.DepartmentID == id).FirstOrDefault();
            DepartmentLocation dl   = db.DepartmentLocations.Where(x => x.DepartmentID == id).FirstOrDefault();

            DepartmentViewModel model = new DepartmentViewModel();

            //model.MyList = new SelectList(from s in db.Employees.ToList()
            //                               select new
            //                               {
            //                                   EmplyeeId = s.EmployeeId,
            //                                   FullName = s.FirstName + " " + s.LastName
            //                               },
            //                      "EmplyeeId",
            //                      "FullName",
            //                      new { dm.EmployeeId });


            //var Selects = (from s in db.Departments
            //               join n in db.DepartmentLocations
            //               on s.DepartmentID equals n.DepartmentID
            //               join m in db.DepartmentManagers
            //               on s.DepartmentID equals m.DepartmentID
            //               join z in db.Employees
            //               on m.DepartmentID equals z.DepartmentID
            //               where m.EmployeeId == z.EmployeeId
            //               select new
            //               {
            //                   DepartmentID = s.DepartmentID,
            //                   EmployeeId = z.EmployeeId,
            //                   Name = s.Name,
            //                   NumberOfEmps = s.NumberOfEmps,
            //                   Location = n.Location,
            //                   StartDate = m.StartDate,
            //                   FirstName = z.FirstName,
            //                   LastName = z.LastName
            //               }).FirstOrDefault();


            model.DepartmentID = dept.DepartmentID;
            model.Name         = db.Departments.Where(m => m.DepartmentID == id).Select(x => x.Name).FirstOrDefault();
            model.NumberOfEmps = db.Departments.Where(m => m.DepartmentID == id).Select(x => x.NumberOfEmps).FirstOrDefault();
            model.Location     = db.DepartmentLocations.Where(m => m.DepartmentID == id).Select(x => x.Location).FirstOrDefault();
            model.StartDate    = db.DepartmentManagers.Where(m => m.DepartmentID == id).Select(x => x.StartDate).FirstOrDefault();
            model.FirstName    = db.DepartmentManagers.Where(m => m.DepartmentID == id).Select(x => x.Employee.FirstName).FirstOrDefault();
            model.LastName     = db.DepartmentManagers.Where(m => m.DepartmentID == id).Select(x => x.Employee.LastName).FirstOrDefault();
            model.EmployeeId   = db.DepartmentManagers.Where(m => m.DepartmentID == id).Select(x => x.EmployeeId).FirstOrDefault();

            //model.DepartmentID = dept.DepartmentID;
            //model.Name = dept.Name;
            //model.Location = dl.Location;
            //model.EmployeeId = dm.EmployeeId;
            //model.StartDate = dm.StartDate;

            TempData["GetLocation"] = model.Location;
            TempData["EmpID"]       = model.EmployeeId;

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            if (dept == null)
            {
                return(HttpNotFound());
            }
            return(View(model));
        }
Exemplo n.º 7
0
        public static void Initialize(EmployeeContext context)
        {
            // Look for any employees.
            if (context.Employees.Any())
            {
                return;   // DB has been seeded
            }

            var dept = new Department[]
            {
                new Department {
                    Name = "Accounting"
                },
                new Department {
                    Name = "IT"
                },
                new Department {
                    Name = "Marketing"
                },
                new Department {
                    Name = "Sales"
                },
                new Department {
                    Name = "Management"
                },
                new Department {
                    Name = "Plant"
                },
                new Department {
                    Name = "Shipping"
                },
                new Department {
                    Name = "Warehouse"
                }
            };

            foreach (Department d in dept)
            {
                context.Departments.Add(d);
            }
            context.SaveChanges();

            var loc = new Location[]
            {
                new Location {
                    Type = Models.Type.Headquarters, Address = "2200 Park Ave", Zipcode = "49696"
                },
                new Location {
                    Type = Models.Type.Warehouse, Address = "2200 Park Ave", Zipcode = "49696"
                },
                new Location {
                    Type = Models.Type.Sales, Address = "2200 Park Ave", Zipcode = "49696"
                },
                new Location {
                    Type = Models.Type.Plant, Address = "2100 Park Ave", Zipcode = "49696"
                },
                new Location {
                    Type = Models.Type.Plant, Address = "6 Hickory Blvd.", Zipcode = "49696"
                },
                new Location {
                    Type = Models.Type.Satellite, Address = "6 Hickory Blvd.", Zipcode = "49696"
                }
            };

            foreach (Location l in loc)
            {
                context.Locations.Add(l);
            }
            context.SaveChanges();

            var emp = new Employee[]
            {
                new Employee {
                    ID = 1012, FirstName = "Freddie", LastName = "Flintstone", HireDate = DateTime.Parse("2020-09-01"), DepartmentID = 1
                },
                new Employee {
                    ID = 1067, FirstName = "Wilma", LastName = "Flintstone", HireDate = DateTime.Parse("2005-07-01"), DepartmentID = 2
                },
                new Employee {
                    ID = 1098, FirstName = "Barney", LastName = "Rubble", HireDate = DateTime.Parse("2021-09-01"), DepartmentID = 3
                },
                new Employee {
                    ID = 100, FirstName = "Judy", LastName = "Jetson", HireDate = DateTime.Parse("2019-02-01"), DepartmentID = 4
                },
                new Employee {
                    ID = 101, FirstName = "Daphne", LastName = "Blake", HireDate = DateTime.Parse("2010-01-01"), DepartmentID = 5
                }
            };

            foreach (Employee e in emp)
            {
                context.Employees.Add(e);
            }
            context.SaveChanges();

            var empBenefits = new Benefits[]
            {
                new Benefits {
                    EmployeeID = 1012, Category = Category.family, Dental = true, Health = true, Vision = true, LifeIns = 100000
                },
                new Benefits {
                    EmployeeID = 1067, Category = Category.none, LifeIns = 100000
                },
                new Benefits {
                    EmployeeID = 100
                },
                new Benefits {
                    EmployeeID = 1098
                },
                new Benefits {
                    EmployeeID = 101, Category = Category.single, Dental = true, Health = true, Vision = true, LifeIns = 50000
                }
            };

            foreach (Benefits b in empBenefits)
            {
                context.Benefits.Add(b);
            }
            context.SaveChanges();

            var deptLoc = new DepartmentLocation[]
            {
                new DepartmentLocation {
                    DepartmentID = 1, LocationID = 1
                },
                new DepartmentLocation {
                    DepartmentID = 2, LocationID = 1
                },
                new DepartmentLocation {
                    DepartmentID = 3, LocationID = 1
                },
                new DepartmentLocation {
                    DepartmentID = 4, LocationID = 1
                },
                new DepartmentLocation {
                    DepartmentID = 5, LocationID = 1
                },
                new DepartmentLocation {
                    DepartmentID = 8, LocationID = 1
                },
                new DepartmentLocation {
                    DepartmentID = 6, LocationID = 4
                },
                new DepartmentLocation {
                    DepartmentID = 7, LocationID = 5
                },
                new DepartmentLocation {
                    DepartmentID = 7, LocationID = 5
                }
            };

            foreach (DepartmentLocation dl in deptLoc)
            {
                context.DepartmentLocation.Add(dl);
            }
            context.SaveChanges();
        }