Example #1
0
        /// <summary>
        /// Methode called when user generate and Index_QR entity,
        /// It takes the ProuctID and COntroller and action name those are passed by the view
        /// looks for its entities in the DB and create a new Index_QR entity with
        /// composed of those entites and also includes the User entity who was logged in
        /// </summary>
        /// <param name="productID">Product of ID to generate</param>
        /// <param name="controllerName">Name of controller, so the ID can be found</param>
        /// <param name="actionName">Name of the action, so the ID can be found</param>
        /// <returns>In case of insert query success it return the same page with the new generated QR
        ///  in case of fail it return an error page</returns>

        public ActionResult Create(long productID, string controllerName, string actionName)
        {
            try
            {
                Controller_QR controller_QR = _unityOfWork.Controller_QR.GetAll().FirstOrDefault(b => b.Name == controllerName);
                Action_QR     action_QR     = _unityOfWork.Action_QR.GetAll().FirstOrDefault(b => b.Name == actionName);
                Product       Product       = _unityOfWork.Product.GetById(productID);
                Index_QR      model         = new Index_QR()
                {
                    Product       = Product,
                    Controller_QR = controller_QR,
                    Action_QR     = action_QR,
                    //ProductID = productID,
                    // ControllerID = controller_QR.ID,
                    UserID   = User.FindFirst(ClaimTypes.NameIdentifier).Value,
                    Created  = DateTime.Now,
                    IsActive = true
                };

                _unityOfWork.Index_QR.Insert(model);
                _unityOfWork.Save();

                return(RedirectToAction("Detail", "Product", new { id = productID }));
            }
            catch
            {
                return(RedirectToAction("Error", "Home"));
            }
        }
 /// <summary>
 /// Creates an new Entitie in Index_QR Table with the passed Parameter Index_QR Object
 /// </summary>
 /// <param name="index_QR">Index_QR object passed from Controller and created from User in View (ProductDetails view)</param>
 public void Insert(Index_QR index_QR)
 {
     if (!QRExist(index_QR))
     {
         _context.Index_QR.Add(index_QR);
         _context.SaveChanges();
     }
 }
        public bool QRExist(Index_QR index_QR)
        {
            var QR = _context.Index_QR.FirstOrDefault(d => d.ProductID == index_QR.Product.ID && d.ActionID == index_QR.Action_QR.ID && d.ControllerID == index_QR.Controller_QR.ID);

            if (QR != null)
            {
                return(true);
            }
            return(false);
        }
 /// <summary>
 /// Check if QR is active
 /// </summary>
 /// <param name="QR">Object of type Index_QR who should be checked</param>
 /// <returns>true if active and false if it is deactivated</returns>
 public static bool IsQRValid(Index_QR QR)
 {
     if (!QR.IsActive)
     {
         return(false);
     }
     else
     {
         return(true);
     }
 }
        /// <summary>
        /// Checks if QR IsActive or if Index_QR passed object
        /// or is null (Mostly in case Index_QR Object wasnt found in the DB)
        /// </summary>
        /// <param name="QR">Object of type Index_QR who validity should be checked</param>
        /// <returns>An string with an errorMessage wich is used in the view</returns>
        public static string CheckQRError(Index_QR QR)
        {
            if (QR == null)
            {
                return(">>> This QR Code is not registered in our System. " +
                       "Probaly this product was deleted of the system, " +
                       "please contact the System Administrator");
            }
            else if (!IsQRValid(QR))
            {
                return(">>> This QR Code is Deactivated");
            }

            return("");
        }
 /// <summary>
 /// Deletes Index_QR entitie from Database
 /// </summary>
 /// <param name="index_QR">Object that should deleted, , managed in Index_QR Admin View by User </param>
 public void Delete(Index_QR index_QR)
 {
     _context.Index_QR.Remove(index_QR);
     _context.SaveChanges();
 }
 /// <summary>
 /// Update the Table Entitie in Database
 /// </summary>
 /// <param name="index_QR">Index_QR object received from Controller, managed in Index_QR Admin View by User</param>
 public void Update(Index_QR index_QR)
 {
     _context.Index_QR.Update(index_QR);
     _context.SaveChanges();
 }