public static VendorEmployeeModel GetVendorEmployee(int ID)
        {
            try
            {
                if (ID != 0)
                {
                    using (RoundTheCornerEntities rc = new RoundTheCornerEntities())
                    {
                        var tblVendorEmployee = rc.TblVendorEmployees.FirstOrDefault(u => u.ID == ID);

                        if (tblVendorEmployee != null)
                        {
                            VendorEmployeeModel vendorEmployee = new VendorEmployeeModel
                            {
                                ID       = tblVendorEmployee.ID,
                                UserID   = tblVendorEmployee.UserID,
                                VendorID = tblVendorEmployee.VendorID
                            };

                            return(vendorEmployee);
                        }

                        throw new Exception("VendorEmployee cannot be found");
                    }
                }
                else
                {
                    throw new Exception("ID cannot be 0");
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemple #2
0
        public ActionResult FireEmployee(int id)
        {
            VendorEmployeeModel     vm   = VendorEmployeeManager.GetVendorEmployee(id);
            EmployeeVendorViewModel evvm = new EmployeeVendorViewModel();

            evvm.User   = UserManager.GetUser(vm.UserID);
            evvm.Vendor = VendorManager.GetVendor(vm.VendorID);

            return(View(evvm));
        }
Exemple #3
0
        public ActionResult AddEmployee(string UserList, VendorEmployeeModel vm)
        {
            UserModel userModel = (UserModel)Session["User"];

            vm.VendorID = VendorManager.GetOwnerVendor(userModel.UserID).VendorID;
            vm.UserID   = int.Parse(UserList);
            VendorEmployeeManager.Insert(vm);

            TempData["Message"] = "Employee has been hired";
            return(RedirectToAction("GetEmployees", "Vendor"));
        }
        // Just a comment
        public static bool Seed()
        {
            VendorEmployeeModel vendorEmployee = new VendorEmployeeModel
            {
                VendorID = 1,
                UserID   = 1,
                ID       = 1
            };

            return(Insert(vendorEmployee));
        }
        public void Update()
        {
            VendorEmployeeModel vendorEmployee = new VendorEmployeeModel
            {
                ID       = 2,
                VendorID = 2,
                UserID   = 2,
            };

            VendorEmployeeManager.Update(vendorEmployee);

            VendorEmployeeModel newVendorEmployee = VendorEmployeeManager.GetVendorEmployee(2);

            Assert.AreEqual(vendorEmployee.ID, newVendorEmployee.ID);
        }
 public static bool Insert(VendorEmployeeModel vendorEmployee)
 {
     try
     {
         using (RoundTheCornerEntities rc = new RoundTheCornerEntities())
         {
             PL.TblVendorEmployee newRow = new TblVendorEmployee()
             {
                 ID       = rc.TblVendorEmployees.Any() ? rc.TblVendorEmployees.Max(u => u.ID) + 1 : 1,
                 VendorID = vendorEmployee.VendorID,
                 UserID   = vendorEmployee.UserID
             };
             rc.TblVendorEmployees.Add(newRow);
             rc.SaveChanges();
             return(true);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
        public static bool Update(VendorEmployeeModel vendorEmployee)
        {
            try
            {
                if (vendorEmployee.ID != 0)
                {
                    using (RoundTheCornerEntities rc = new RoundTheCornerEntities())
                    {
                        TblVendorEmployee tblVendorEmployee = rc.TblVendorEmployees.FirstOrDefault(u => u.ID == vendorEmployee.ID);

                        if (tblVendorEmployee != null)
                        {
                            tblVendorEmployee.ID       = vendorEmployee.ID;
                            tblVendorEmployee.UserID   = vendorEmployee.UserID;
                            tblVendorEmployee.VendorID = vendorEmployee.VendorID;


                            rc.SaveChanges();
                            return(true);
                        }
                        else
                        {
                            throw new Exception("VendorEmployee was not found");
                        }
                    }
                }
                else
                {
                    throw new Exception("Must have a valID ID");
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }