// @desc Updates holiday request to accepted status
        public void accept_holiday(int holiday_id)
        {
            Holiday holiday = db.Holidays.FirstOrDefault(h => h.Holiday_ID == holiday_id);

            holiday.holiday_status = "Accepted";
            db.SaveChanges();
        }
Beispiel #2
0
        public ActionResult Create([Bind(Include = "Id,Nombre,Apellidos,Documento_de_identidad,Fecha_de_creacion")] Contactoss contactoss)
        {
            if (ModelState.IsValid)
            {
                db.Contactoss.Add(contactoss);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(contactoss));
        }
        public ActionResult Create([Bind(Include = "Id,Motivo_de_visita,Fechaentrada,Fechasalida,Horasalida,Nombre_completo,Contacto_que_lo_recibio")] Visitas visitas)
        {
            if (ModelState.IsValid)
            {
                db.Visitas.Add(visitas);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(visitas));
        }
        // @desc Adds new employee to database
        public void add_employee(String name, String email, String password, String employee_role, String department, int holiday_days_available = 30, String system_role = "User")
        {
            // Bind parameters passed to Employee object
            Employee new_user = new Employee
            {
                email                  = email,
                name_                  = name,
                password               = password,
                employee_role          = employee_role,
                department             = department,
                join_date              = DateTime.Today,
                holiday_days_available = holiday_days_available,  // Every employee starts with 30 days holiday
                system_role            = system_role
            };

            db.Employees.Add(new_user);
            db.SaveChanges();
        }
        // private static UserInfo _users = new UserInfo();

        protected void Page_Load(object sender, EventArgs e)
        {
            FinalEntities con  = new FinalEntities();
            UserInfo      user = new UserInfo();

            user.Email           = Request.Form["email"];
            user.Gender          = Request.Form["gender"];
            user.Password        = Request.Form["password"];
            user.Confirmpassword = Request.Form["conpassword"];
            user.Username        = Request.Form["username"];
            con.UserInfoes.Add(user);
            con.SaveChanges();
        }
    //insert a product method
    public string InSetProduct(Product product)
    {
        try
        {
            FinalEntities db = new FinalEntities();
            db.Products.Add(product);
            db.SaveChanges();//commit
            //return the got product.Name for the lable which is resultLabel to display
            return product.Name + " was successfully inserted.";
        }
        catch (Exception e)
        {

            return e.Message + "no idea";
        }
    }
    //insert product type method
    public string InSetProductType(ProductType productType)
    {
        try
        {

            FinalEntities db = new FinalEntities();
            db.ProductTypes.Add(productType);
            db.SaveChanges();//commit
            return productType.TypeDescreption + " was successfully inserted.";
        }
        catch (Exception e)
        {

            return e.Message;
        }
    }
    //delete a product by the id
    public string DeleteProduct(int id)
    {
        try
        {
            //get the database
            FinalEntities db = new FinalEntities();
            //get the table from db
            Product pt = db.Products.Find(id);
            //attach() method Attaches a disconnected or "detached" entity to a new DataContext when original values are required for optimistic concurrency checks.
            db.Products.Attach(pt);
            //remove the product type by the id
            db.Products.Remove(pt);
            //save it
            db.SaveChanges();
            //return the got name for the lable which is resultLabel
            return pt.Name + "was successfully deleted.";
        }
        catch (Exception e)
        {

            return e.Message;
        }
    }
    //update the product by the id
    public string UpdateProduct(int id, Product product)
    {
        try
        {
            //get the database
            FinalEntities db = new FinalEntities();
            //get the table from db
            Product pt = db.Products.Find(id);
            //use the pt id to get all the variables from db
            pt.Name = product.Name;
            pt.Image = product.Image;
            pt.Price = product.Price;
            pt.Type = product.Type;
            pt.Quantity = product.Quantity;
            pt.Description = product.Description;
            //commit it save it
            db.SaveChanges();
            //return the got Name for the lable which is resultLabel to display
            return product.Name + "was successfully updated.";
        }
        catch (Exception e)
        {

            return e.Message;
        }
    }
    //update product type by the id
    public string UpdateProductType(int id, ProductType productType)
    {
        try
        {
            //get the database
            FinalEntities db = new FinalEntities();
            //get the table from db
            ProductType pt = db.ProductTypes.Find(id);
            //use the pt id to get the TypeDescreption from db
            pt.TypeDescreption = productType.TypeDescreption;
            //commit it save it
            db.SaveChanges();
            //return the got TypeDescreption for the lable which is resultLabel
            return productType.TypeDescreption + "was successfully updated.";
        }
        catch (Exception e)
        {

            return e.Message;
        }
    }